Skip to content

Commit 8be6a34

Browse files
committed
fix(baremetal): update offer and refacto tests
1 parent 4b9b96e commit 8be6a34

26 files changed

+11063
-7978
lines changed

internal/namespaces/baremetal/v1/custom_server_create_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,43 @@ import (
99
baremetalSDK "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1"
1010
)
1111

12+
const (
13+
offerNameNVME = "EM-I215E-NVME"
14+
offerNameSATA = "EM-B111X-SATA"
15+
zone = "fr-par-2"
16+
)
17+
1218
// All test below should succeed to create an instance.
1319
func Test_CreateServer(t *testing.T) {
1420
// Simple use cases
1521
t.Run("Simple", func(t *testing.T) {
1622
t.Run("Default", core.Test(&core.TestConfig{
1723
Commands: baremetal.GetCommands(),
18-
Cmd: "scw baremetal server create zone=fr-par-1 type=EM-B220E-NVME -w",
24+
Cmd: "scw baremetal server create zone=" + zone + " type=" + offerNameNVME + " -w",
1925
Check: core.TestCheckCombine(
2026
core.TestCheckGolden(),
2127
core.TestCheckExitCode(0),
2228
),
23-
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=fr-par-1"),
29+
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=" + zone),
2430
},
2531
))
2632

2733
t.Run("With name", core.Test(&core.TestConfig{
2834
Commands: baremetal.GetCommands(),
29-
Cmd: "scw baremetal server create name=test-create-server-with-name zone=fr-par-1 type=EM-B220E-NVME -w",
35+
Cmd: "scw baremetal server create name=test-create-server-with-name zone=" + zone + " type=" + offerNameNVME + " -w",
3036
Check: core.TestCheckCombine(
3137
func(t *testing.T, ctx *core.CheckFuncCtx) {
3238
t.Helper()
3339
assert.Equal(t, "test-create-server-with-name", ctx.Result.(*baremetalSDK.Server).Name)
3440
},
3541
core.TestCheckExitCode(0),
3642
),
37-
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=fr-par-1"),
43+
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=" + zone),
3844
}))
3945

4046
t.Run("Tags", core.Test(&core.TestConfig{
4147
Commands: baremetal.GetCommands(),
42-
Cmd: "scw baremetal server create tags.0=prod tags.1=blue zone=fr-par-1 type=EM-B220E-NVME -w",
48+
Cmd: "scw baremetal server create tags.0=prod tags.1=blue zone=" + zone + " type=" + offerNameNVME + " -w",
4349
Check: core.TestCheckCombine(
4450
func(t *testing.T, ctx *core.CheckFuncCtx) {
4551
t.Helper()
@@ -48,7 +54,7 @@ func Test_CreateServer(t *testing.T) {
4854
},
4955
core.TestCheckExitCode(0),
5056
),
51-
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=fr-par-1"),
57+
AfterFunc: core.ExecAfterCmd("scw baremetal server delete {{ .CmdResult.ID }} zone=" + zone),
5258
}))
5359
})
5460
}

internal/namespaces/baremetal/v1/custom_server_fip_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ func Test_CreateFlexibleIPInteractive(t *testing.T) {
1919
t.Run("Simple Interactive", core.Test(&core.TestConfig{
2020
Commands: cmds,
2121
BeforeFunc: core.BeforeFuncCombine(
22-
createServerAndWaitDefault("Server"),
22+
createServerAndWait("Server"),
2323
),
24-
Cmd: "scw baremetal server add-flexible-ip {{ .Server.ID }}",
24+
Cmd: "scw baremetal server add-flexible-ip {{ .Server.ID }} zone=" + zone,
2525
Check: core.TestCheckCombine(
2626
core.TestCheckGolden(),
2727
),
2828
AfterFunc: core.AfterFuncCombine(
29-
deleteServerDefault("Server"),
30-
core.ExecAfterCmd("scw fip ip delete {{ .CmdResult.ID }}"),
29+
deleteServer("Server"),
30+
core.ExecAfterCmd("scw fip ip delete {{ .CmdResult.ID }} zone="+zone),
3131
),
3232
PromptResponseMocks: promptResponse,
3333
}))
@@ -40,15 +40,15 @@ func Test_CreateFlexibleIP(t *testing.T) {
4040
t.Run("Simple", core.Test(&core.TestConfig{
4141
Commands: cmds,
4242
BeforeFunc: core.BeforeFuncCombine(
43-
createServerAndWaitDefault("Server"),
43+
createServerAndWait("Server"),
4444
),
45-
Cmd: "scw baremetal server add-flexible-ip {{ .Server.ID }} ip-type=IPv4",
45+
Cmd: "scw baremetal server add-flexible-ip {{ .Server.ID }} ip-type=IPv4 zone=" + zone,
4646
Check: core.TestCheckCombine(
4747
core.TestCheckGolden(),
4848
),
4949
AfterFunc: core.AfterFuncCombine(
50-
deleteServerDefault("Server"),
51-
core.ExecAfterCmd("scw fip ip delete {{ .CmdResult.ID }}"),
50+
deleteServer("Server"),
51+
core.ExecAfterCmd("scw fip ip delete {{ .CmdResult.ID }} zone="+zone),
5252
),
5353
}))
5454
}

internal/namespaces/baremetal/v1/custom_server_install_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func Test_InstallServer(t *testing.T) {
2323
createServerAndWait("Server"),
2424
),
2525
Commands: cmds,
26-
Cmd: "scw baremetal server install {{ .Server.ID }} zone=nl-ams-1 hostname=test-install-server ssh-key-ids.0={{ .key.ID }} os-id=" + osID + " -w",
26+
Cmd: "scw baremetal server install {{ .Server.ID }} zone=" + zone + " hostname=test-install-server ssh-key-ids.0={{ .key.ID }} os-id=" + osID + " -w",
2727
Check: core.TestCheckCombine(
2828
core.TestCheckGolden(),
2929
core.TestCheckExitCode(0),
@@ -40,7 +40,7 @@ func Test_InstallServer(t *testing.T) {
4040
addSSH("key", sshKey),
4141
createServerAndWait("Server"),
4242
),
43-
Cmd: "scw baremetal server install {{ .Server.ID }} zone=nl-ams-1 hostname=test-install-server all-ssh-keys=true os-id=" + osID + " -w",
43+
Cmd: "scw baremetal server install {{ .Server.ID }} zone=" + zone + " hostname=test-install-server all-ssh-keys=true os-id=" + osID + " -w",
4444
Check: core.TestCheckCombine(
4545
core.TestCheckGolden(),
4646
core.TestCheckExitCode(0),

internal/namespaces/baremetal/v1/custom_server_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111

1212
func Test_StartServerErrors(t *testing.T) {
1313
t.Run("Error: cannot be started while not delivered", core.Test(&core.TestConfig{
14-
BeforeFunc: createServer("Server"),
14+
BeforeFunc: createServer("Server", offerNameSATA),
1515
Commands: baremetal.GetCommands(),
16-
Cmd: "scw baremetal server start zone=nl-ams-1 {{ .Server.ID }}",
16+
Cmd: "scw baremetal server start zone=" + zone + " {{ .Server.ID }}",
1717
Check: core.TestCheckCombine(
1818
core.TestCheckGolden(),
1919
core.TestCheckExitCode(1),
@@ -37,9 +37,9 @@ func Test_StartServerErrors(t *testing.T) {
3737

3838
func Test_StopServerErrors(t *testing.T) {
3939
t.Run("Error: cannot be stopped while not delivered", core.Test(&core.TestConfig{
40-
BeforeFunc: createServer("Server"),
40+
BeforeFunc: createServer("Server", offerNameSATA),
4141
Commands: baremetal.GetCommands(),
42-
Cmd: "scw baremetal server stop zone=nl-ams-1 {{ .Server.ID }}",
42+
Cmd: "scw baremetal server stop zone=" + zone + " {{ .Server.ID }}",
4343
Check: core.TestCheckCombine(
4444
core.TestCheckGolden(),
4545
core.TestCheckExitCode(1),
@@ -63,9 +63,9 @@ func Test_StopServerErrors(t *testing.T) {
6363

6464
func Test_RebootServerErrors(t *testing.T) {
6565
t.Run("Error: cannot be rebooted while not delivered", core.Test(&core.TestConfig{
66-
BeforeFunc: createServer("Server"),
66+
BeforeFunc: createServer("Server", offerNameSATA),
6767
Commands: baremetal.GetCommands(),
68-
Cmd: "scw baremetal server reboot zone-nl-ams-1 {{ .Server.ID }}",
68+
Cmd: "scw baremetal server reboot zone=" + zone + " {{ .Server.ID }}",
6969
Check: core.TestCheckCombine(
7070
core.TestCheckGolden(),
7171
core.TestCheckExitCode(1),

internal/namespaces/baremetal/v1/helpers_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,19 @@ import (
99
// createServerAndWait creates a baremetal instance
1010
// register it in the context Meta at metaKey.
1111
func createServerAndWait(metaKey string) core.BeforeFunc {
12-
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create zone=nl-ams-1 type=GP-BM2-S -w")
12+
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create type="+offerNameNVME+" zone="+zone+" -w")
1313
}
1414

15-
func createServerAndWaitDefault(metaKey string) core.BeforeFunc {
16-
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create type=EM-B112X-SSD -w")
15+
func createServer(metaKey string, offer string) core.BeforeFunc {
16+
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create zone="+zone+" type="+offer)
1717
}
1818

19-
func createServer(metaKey string) core.BeforeFunc {
20-
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create zone=nl-ams-1 type=GP-BM2-S")
21-
}
22-
23-
// deleteServer deletes a server
19+
// deleteServer deletes a serv er
2420
// previously registered in the context Meta at metaKey.
2521
//
2622
//nolint:unparam
2723
func deleteServer(metaKey string) core.AfterFunc {
28-
return core.ExecAfterCmd(fmt.Sprintf("scw baremetal server delete zone=nl-ams-1 {{ .%s.ID }}", metaKey))
29-
}
30-
31-
func deleteServerDefault(metaKey string) core.AfterFunc {
32-
return core.ExecAfterCmd(fmt.Sprintf("scw baremetal server delete {{ .%s.ID }}", metaKey))
24+
return core.ExecAfterCmd(fmt.Sprintf("scw baremetal server delete {{ .%s.ID }} zone=%s", metaKey, zone))
3325
}
3426

3527
// add an ssh key with a given meta key

0 commit comments

Comments
 (0)