Skip to content

Commit 9b7f5b5

Browse files
committed
feat(baremetal):add of tests
1 parent 9bc7ad9 commit 9b7f5b5

File tree

4 files changed

+1501
-2
lines changed

4 files changed

+1501
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package baremetal
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
8+
)
9+
10+
func Test_CreateFlexibleIP(t *testing.T) {
11+
promptResponse := []string{
12+
`" "`,
13+
"description of flexibleIP",
14+
"tags flexible IP",
15+
}
16+
interactive.IsInteractive = true
17+
t.Run("Simple", core.Test(&core.TestConfig{
18+
Commands: GetCommands(),
19+
BeforeFunc: core.BeforeFuncCombine(
20+
createServerAndWaitDefault("Server"),
21+
),
22+
Cmd: "scw baremetal server add-flexible-ip {{ .Server.ID }}",
23+
Check: core.TestCheckCombine(
24+
core.TestCheckGolden(),
25+
),
26+
AfterFunc: core.AfterFuncCombine(
27+
deleteServerDefault("Server"),
28+
),
29+
PromptResponseMocks: promptResponse,
30+
}))
31+
}

internal/namespaces/baremetal/v1/helpers_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ import (
44
"github.com/scaleway/scaleway-cli/v2/internal/core"
55
)
66

7+
const id = ".ID }}"
8+
79
// createServerAndWait creates a baremetal instance
810
// register it in the context Meta at metaKey.
911
func createServerAndWait(metaKey string) core.BeforeFunc {
1012
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create zone=nl-ams-1 type=GP-BM2-S -w")
1113
}
1214

15+
func createServerAndWaitDefault(metaKey string) core.BeforeFunc {
16+
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create type=EM-B112X-SSD -w")
17+
}
18+
1319
func createServer(metaKey string) core.BeforeFunc {
1420
return core.ExecStoreBeforeCmd(metaKey, "scw baremetal server create zone=nl-ams-1 type=GP-BM2-S")
1521
}
@@ -19,7 +25,11 @@ func createServer(metaKey string) core.BeforeFunc {
1925
//
2026
//nolint:unparam
2127
func deleteServer(metaKey string) core.AfterFunc {
22-
return core.ExecAfterCmd("scw baremetal server delete zone=nl-ams-1 {{ ." + metaKey + ".ID }}")
28+
return core.ExecAfterCmd("scw baremetal server delete zone=nl-ams-1 {{ ." + metaKey + id)
29+
}
30+
31+
func deleteServerDefault(metaKey string) core.AfterFunc {
32+
return core.ExecAfterCmd("scw baremetal server delete {{ ." + metaKey + id)
2333
}
2434

2535
// add an ssh key with a given meta key
@@ -34,5 +44,5 @@ func addSSH(metaKey string, key string) core.BeforeFunc {
3444

3545
// delete an ssh key with a given meta key
3646
func deleteSSH(metaKey string) core.AfterFunc {
37-
return core.ExecAfterCmd("scw iam ssh-key delete {{ ." + metaKey + ".ID }}")
47+
return core.ExecAfterCmd("scw iam ssh-key delete {{ ." + metaKey + id)
3848
}

0 commit comments

Comments
 (0)