Skip to content

Commit 3ae3ad6

Browse files
committed
fix tests
1 parent 355c261 commit 3ae3ad6

22 files changed

Lines changed: 9161 additions & 4543 deletions

internal/namespaces/instance/v1/custom_image_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func Test_ImageCreate(t *testing.T) {
1313
t.Run("Create simple image", core.Test(&core.TestConfig{
1414
BeforeFunc: core.BeforeFuncCombine(
15-
createServer("Server"),
15+
createServerBionic("Server"),
1616
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
1717
),
1818
Commands: GetCommands(),
@@ -72,7 +72,7 @@ func Test_ImageDelete(t *testing.T) {
7272

7373
func createImage(metaKey string) core.BeforeFunc {
7474
return core.BeforeFuncCombine(
75-
createServer("Server"),
75+
createServerBionic("Server"),
7676
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
7777
core.ExecStoreBeforeCmd(metaKey, `scw instance image create snapshot-id={{ .Snapshot.Snapshot.ID }} arch=x86_64`),
7878
)

internal/namespaces/instance/v1/custom_privatenics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func Test_ListNICs(t *testing.T) {
1515
Commands: cmds,
1616
BeforeFunc: core.BeforeFuncCombine(
1717
createPN(),
18-
createServer("Server"),
18+
createServerBionic("Server"),
1919
createNIC(),
2020
),
2121
Cmd: "scw instance private-nic list server-id={{ .Server.ID }}",
@@ -46,7 +46,7 @@ func Test_GetPrivateNIC(t *testing.T) {
4646
Commands: cmds,
4747
BeforeFunc: core.BeforeFuncCombine(
4848
createPN(),
49-
createServer("Server"),
49+
createServerBionic("Server"),
5050
createNIC(),
5151
),
5252
Cmd: "scw instance private-nic get server-id={{ .Server.ID }} private-nic-id={{ .NIC.PrivateNic.MacAddress }}",

internal/namespaces/instance/v1/custom_server_create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func Test_CreateServer(t *testing.T) {
2323
t.Run("Simple", func(t *testing.T) {
2424
t.Run("Default", core.Test(&core.TestConfig{
2525
Commands: GetCommands(),
26-
Cmd: "scw instance server create image=ubuntu_bionic stopped=true",
26+
Cmd: "scw instance server create image=ubuntu_jammy stopped=true",
2727
Check: core.TestCheckCombine(
2828
core.TestCheckGolden(),
2929
func(t *testing.T, ctx *core.CheckFuncCtx) {
30-
assert.Equal(t, "Ubuntu 18.04 Bionic Beaver", ctx.Result.(*instance.Server).Image.Name)
30+
assert.Equal(t, "Ubuntu 22.04 Jammy Jellyfish", ctx.Result.(*instance.Server).Image.Name)
3131
},
3232
core.TestCheckExitCode(0),
3333
),

internal/namespaces/instance/v1/custom_server_ssh_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func Test_ServerSSH(t *testing.T) {
1010
t.Run("Simple", core.Test(&core.TestConfig{
1111
Commands: GetCommands(),
1212
BeforeFunc: core.BeforeFuncCombine(
13-
createServer("Server"),
13+
createServerBionic("Server"),
1414
startServer("Server"),
1515
),
1616
Cmd: "scw instance server ssh {{ .Server.ID }}",
@@ -29,7 +29,7 @@ func Test_ServerSSH(t *testing.T) {
2929
t.Run("With-Exit-Code", core.Test(&core.TestConfig{
3030
Commands: GetCommands(),
3131
BeforeFunc: core.BeforeFuncCombine(
32-
createServer("Server"),
32+
createServerBionic("Server"),
3333
startServer("Server"),
3434
),
3535
Cmd: "scw instance server ssh {{ .Server.ID }}",
@@ -47,7 +47,7 @@ func Test_ServerSSH(t *testing.T) {
4747

4848
t.Run("Stopped server", core.Test(&core.TestConfig{
4949
Commands: GetCommands(),
50-
BeforeFunc: createServer("Server"),
50+
BeforeFunc: createServerBionic("Server"),
5151
Cmd: "scw instance server ssh {{ .Server.ID }}",
5252
Check: core.TestCheckCombine(
5353
core.TestCheckGolden(),

internal/namespaces/instance/v1/custom_server_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
1616
t.Run("simple block volume", core.Test(&core.TestConfig{
1717
Commands: GetCommands(),
1818
BeforeFunc: core.BeforeFuncCombine(
19-
createServer("Server"),
19+
createServerBionic("Server"),
2020
createVolume("Volume", 10, instance.VolumeVolumeTypeBSSD),
2121
),
2222
Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}",
@@ -33,7 +33,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
3333
t.Run("simple local volume", core.Test(&core.TestConfig{
3434
Commands: GetCommands(),
3535
BeforeFunc: core.BeforeFuncCombine(
36-
createServer("Server"),
36+
createServerBionic("Server"),
3737
createVolume("Volume", 10, instance.VolumeVolumeTypeLSSD),
3838
),
3939
Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}",
@@ -49,7 +49,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
4949

5050
t.Run("invalid volume UUID", core.Test(&core.TestConfig{
5151
Commands: GetCommands(),
52-
BeforeFunc: createServer("Server"),
52+
BeforeFunc: createServerBionic("Server"),
5353
Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id=11111111-1111-1111-1111-111111111111",
5454
Check: core.TestCheckCombine(
5555
core.TestCheckGolden(),
@@ -79,7 +79,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
7979

8080
t.Run("invalid volume UUID", core.Test(&core.TestConfig{
8181
Commands: GetCommands(),
82-
BeforeFunc: createServer("Server"),
82+
BeforeFunc: createServerBionic("Server"),
8383
Cmd: "scw instance server detach-volume volume-id=11111111-1111-1111-1111-111111111111",
8484
Check: core.TestCheckCombine(
8585
core.TestCheckGolden(),
@@ -95,7 +95,7 @@ func Test_ServerUpdateCustom(t *testing.T) {
9595
// IP cases.
9696
t.Run("Try to remove ip from server without ip", core.Test(&core.TestConfig{
9797
Commands: GetCommands(),
98-
BeforeFunc: createServer("Server"),
98+
BeforeFunc: createServerBionic("Server"),
9999
Cmd: "scw instance server update {{ .Server.ID }} ip=none",
100100
Check: core.TestCheckCombine(
101101
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -109,7 +109,7 @@ func Test_ServerUpdateCustom(t *testing.T) {
109109
t.Run("Update server ip from server without ip", core.Test(&core.TestConfig{
110110
Commands: GetCommands(),
111111
BeforeFunc: core.BeforeFuncCombine(
112-
createServer("Server"),
112+
createServerBionic("Server"),
113113
createIP("IP"),
114114
),
115115
Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP.Address }}",
@@ -125,7 +125,7 @@ func Test_ServerUpdateCustom(t *testing.T) {
125125
t.Run("Update server ip from server with ip", core.Test(&core.TestConfig{
126126
Commands: GetCommands(),
127127
BeforeFunc: core.BeforeFuncCombine(
128-
createServer("Server"),
128+
createServerBionic("Server"),
129129
createIP("IP1"),
130130
createIP("IP2"),
131131

@@ -205,7 +205,7 @@ func Test_ServerUpdateCustom(t *testing.T) {
205205
t.Run("valid simple block volume", core.Test(&core.TestConfig{
206206
Commands: GetCommands(),
207207
BeforeFunc: core.BeforeFuncCombine(
208-
createServer("Server"),
208+
createServerBionic("Server"),
209209
createVolume("Volume", 10, instance.VolumeVolumeTypeBSSD),
210210
),
211211
Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`,

internal/namespaces/instance/v1/custom_ssh_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Test_SSHConfigInstall(t *testing.T) {
1616
t.Run("Install config and create default", core.Test(&core.TestConfig{
1717
TmpHomeDir: true,
1818
Commands: GetCommands(),
19-
BeforeFunc: createServer("Server"),
19+
BeforeFunc: createServerBionic("Server"),
2020
Args: []string{"scw", "instance", "ssh", "install-config"},
2121
Check: core.TestCheckCombine(
2222
core.TestCheckGoldenAndReplacePatterns(
@@ -56,7 +56,7 @@ func Test_SSHConfigInstall(t *testing.T) {
5656

5757
return nil
5858
},
59-
createServer("Server"),
59+
createServerBionic("Server"),
6060
),
6161
Args: []string{"scw", "instance", "ssh", "install-config"},
6262
Check: core.TestCheckCombine(

internal/namespaces/instance/v1/custom_ssh_key_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_SSHKey(t *testing.T) {
3737

3838
t.Run("Add key", core.Test(&core.TestConfig{
3939
Commands: GetCommands(),
40-
BeforeFunc: createServer("Server"),
40+
BeforeFunc: createServerBionic("Server"),
4141
Args: []string{"scw", "instance", "ssh", "add-key", "server-id={{.Server.ID}}", "public-key=" + sshKey},
4242
Check: core.TestCheckCombine(
4343
core.TestCheckGolden(),
@@ -57,7 +57,7 @@ func Test_SSHKey(t *testing.T) {
5757
t.Run("List keys", core.Test(&core.TestConfig{
5858
Commands: GetCommands(),
5959
BeforeFunc: core.BeforeFuncCombine(
60-
createServer("Server"),
60+
createServerBionic("Server"),
6161
addSSHKey("Server", sshKey),
6262
addSSHKey("Server", sshKey2),
6363
),
@@ -76,7 +76,7 @@ func Test_SSHKey(t *testing.T) {
7676
t.Run("Remove key", core.Test(&core.TestConfig{
7777
Commands: GetCommands(),
7878
BeforeFunc: core.BeforeFuncCombine(
79-
createServer("Server"),
79+
createServerBionic("Server"),
8080
addSSHKey("Server", sshKey),
8181
addSSHKey("Server", sshKey2),
8282
),

internal/namespaces/instance/v1/custom_user_data_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func Test_UserDataGet(t *testing.T) {
1111
t.Run("Get an existing key", core.Test(&core.TestConfig{
1212
BeforeFunc: core.BeforeFuncCombine(
13-
createServer("Server"),
13+
createServerBionic("Server"),
1414
core.ExecBeforeCmd("scw instance user-data set server-id={{.Server.ID}} key=happy content=true"),
1515
),
1616
Commands: GetCommands(),
@@ -23,7 +23,7 @@ func Test_UserDataGet(t *testing.T) {
2323
}))
2424

2525
t.Run("Get an nonexistent key", core.Test(&core.TestConfig{
26-
BeforeFunc: createServer("Server"),
26+
BeforeFunc: createServerBionic("Server"),
2727
Commands: GetCommands(),
2828
Cmd: "scw instance user-data get server-id={{.Server.ID}} key=happy",
2929
AfterFunc: deleteServer("Server"),
@@ -37,7 +37,7 @@ func Test_UserDataGet(t *testing.T) {
3737
func Test_UserDataList(t *testing.T) {
3838
t.Run("Simple", core.Test(&core.TestConfig{
3939
BeforeFunc: core.BeforeFuncCombine(
40-
createServer("Server"),
40+
createServerBionic("Server"),
4141
core.ExecBeforeCmd("scw instance user-data set server-id={{ .Server.ID }} key=foo content=bar"),
4242
core.ExecBeforeCmd("scw instance user-data set server-id={{ .Server.ID }} key=bar content=foo"),
4343
),

internal/namespaces/instance/v1/helpers_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ import (
1212
// Server
1313
//
1414

15-
// createServer creates a stopped ubuntu-bionic server and
15+
// createServerBionic creates a stopped ubuntu-bionic server and
1616
// register it in the context Meta at metaKey.
1717
//
1818
//nolint:unparam
19-
func createServer(metaKey string) core.BeforeFunc {
19+
func createServerBionic(metaKey string) core.BeforeFunc {
2020
return core.ExecStoreBeforeCmd(metaKey, "scw instance server create stopped=true image=ubuntu-bionic")
2121
}
2222

23+
func createServer(metaKey string) core.BeforeFunc {
24+
return core.ExecStoreBeforeCmd(metaKey, "scw instance server create stopped=true image=ubuntu-jammy")
25+
}
26+
2327
// createServer creates a stopped ubuntu-bionic server and
2428
// register it in the context Meta at metaKey.
2529
func startServer(metaKey string) core.BeforeFunc {

internal/namespaces/instance/v1/instance_cli_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_ListServer(t *testing.T) {
2424
func Test_GetServer(t *testing.T) {
2525
t.Run("Simple", core.Test(&core.TestConfig{
2626
Commands: GetCommands(),
27-
BeforeFunc: createServer("Server"),
27+
BeforeFunc: createServerBionic("Server"),
2828
Cmd: "scw instance server get {{ .Server.ID }}",
2929
Check: core.TestCheckCombine(
3030
core.TestCheckGolden(),
@@ -61,7 +61,7 @@ func Test_CreateVolume(t *testing.T) {
6161
func Test_ServerUpdate(t *testing.T) {
6262
t.Run("Simple", core.Test(&core.TestConfig{
6363
Commands: GetCommands(),
64-
BeforeFunc: createServer("Server"),
64+
BeforeFunc: createServerBionic("Server"),
6565
Cmd: "scw instance server update {{ .Server.ID }}",
6666
Check: core.TestCheckCombine(
6767
core.TestCheckExitCode(0),
@@ -72,7 +72,7 @@ func Test_ServerUpdate(t *testing.T) {
7272

7373
t.Run("No initial placement group & placement-group-id=none", core.Test(&core.TestConfig{
7474
Commands: GetCommands(),
75-
BeforeFunc: createServer("Server"),
75+
BeforeFunc: createServerBionic("Server"),
7676
Cmd: "scw instance server update {{ .Server.ID }} placement-group-id=none",
7777
Check: core.TestCheckCombine(
7878
func(t *testing.T, ctx *core.CheckFuncCtx) {
@@ -88,7 +88,7 @@ func Test_ServerUpdate(t *testing.T) {
8888
Commands: GetCommands(),
8989
BeforeFunc: core.BeforeFuncCombine(
9090
createPlacementGroup("PlacementGroup"),
91-
createServer("Server"),
91+
createServerBionic("Server"),
9292
),
9393
Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`,
9494
Check: core.TestCheckCombine(
@@ -109,7 +109,7 @@ func Test_ServerUpdate(t *testing.T) {
109109

110110
t.Run(`No initial placement group & placement-group-id=<valid, but non existing pg id>`, core.Test(&core.TestConfig{
111111
Commands: GetCommands(),
112-
BeforeFunc: createServer("Server"),
112+
BeforeFunc: createServerBionic("Server"),
113113
Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=11111111-1111-1111-1111-111111111111`,
114114
Check: core.TestCheckCombine(
115115
core.TestCheckExitCode(1),
@@ -120,7 +120,7 @@ func Test_ServerUpdate(t *testing.T) {
120120

121121
t.Run(`No initial placement group & placement-group-id=<invalid pg id>`, core.Test(&core.TestConfig{
122122
Commands: GetCommands(),
123-
BeforeFunc: createServer("Server"),
123+
BeforeFunc: createServerBionic("Server"),
124124
Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=1111111`,
125125
Check: core.TestCheckCombine(
126126
core.TestCheckExitCode(1),
@@ -202,7 +202,7 @@ func Test_ServerUpdate(t *testing.T) {
202202
func Test_SnapshotCreate(t *testing.T) {
203203
t.Run("simple", core.Test(&core.TestConfig{
204204
Commands: GetCommands(),
205-
BeforeFunc: createServer("Server"),
205+
BeforeFunc: createServerBionic("Server"),
206206
Cmd: `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`,
207207
Check: core.TestCheckCombine(
208208
core.TestCheckGolden(),

0 commit comments

Comments
 (0)