Skip to content

Commit

Permalink
update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Oct 24, 2024
1 parent 7449216 commit da9d862
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
12 changes: 6 additions & 6 deletions internal/namespaces/instance/v1/custom_server_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("without IP", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu-jammy -w")),
Cmd: `scw instance server terminate {{ .Server.ID }}`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -40,7 +40,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("with IP", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu-jammy -w")),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -61,7 +61,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("without block", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu-jammy additional-volumes.0=block:10G -w")),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=false`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -76,7 +76,7 @@ func Test_ServerTerminate(t *testing.T) {

t.Run("with block", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu-jammy additional-volumes.0=block:10G -w"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu-jammy additional-volumes.0=block:10G -w")),
Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=true -w`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -103,7 +103,7 @@ func Test_ServerTerminate(t *testing.T) {
func Test_ServerBackup(t *testing.T) {
t.Run("simple", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu-jammy"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("stopped=true image=ubuntu-jammy")),
Cmd: `scw instance server backup {{ .Server.ID }} name=backup`,
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand All @@ -119,7 +119,7 @@ func Test_ServerBackup(t *testing.T) {
func Test_ServerAction(t *testing.T) {
t.Run("manual poweron", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create stopped=true image=ubuntu_jammy"),
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("stopped=true image=ubuntu_jammy")),
Cmd: `scw instance server action {{ .Server.ID }} action=poweron --wait`,
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
Expand Down
1 change: 0 additions & 1 deletion internal/namespaces/instance/v1/custom_server_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func serverCreateCommand() *core.Command {
{
Name: "type",
Short: "Server commercial type (help: https://www.scaleway.com/en/docs/compute/instances/reference-content/choosing-instance-type/)",
Default: core.DefaultValueSetter("DEV1-S"),
Required: true,
ValidateFunc: func(_ *core.ArgSpec, _ interface{}) error {
// Allow all commercial types
Expand Down
24 changes: 12 additions & 12 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func Test_CreateServer(t *testing.T) {
t.Run("valid single local snapshot", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu_bionic root-volume=local:20GB stopped=true"),
core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu_bionic root-volume=local:20GB stopped=true")),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:{{ .Snapshot.Snapshot.ID }} stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=local:{{ .Snapshot.Snapshot.ID }} stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -155,10 +155,10 @@ func Test_CreateServer(t *testing.T) {
t.Run("valid single local snapshot without image", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu_bionic root-volume=local:20GB stopped=true"),
core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu_bionic root-volume=local:20GB stopped=true")),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
),
Cmd: "scw instance server create image=none root-volume=local:{{ .Snapshot.Snapshot.ID }} stopped=true",
Cmd: testServerCommand("image=none root-volume=local:{{ .Snapshot.Snapshot.ID }} stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand Down Expand Up @@ -192,10 +192,10 @@ func Test_CreateServer(t *testing.T) {
t.Run("valid double snapshot", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu_bionic root-volume=local:20GB stopped=true"),
core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu_bionic root-volume=local:20GB stopped=true")),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create unified=true volume-id={{ (index .Server.Volumes "0").ID }}`),
),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=block:{{ .Snapshot.Snapshot.ID }} additional-volumes.0=local:{{ .Snapshot.Snapshot.ID }} stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=block:{{ .Snapshot.Snapshot.ID }} additional-volumes.0=local:{{ .Snapshot.Snapshot.ID }} stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand Down Expand Up @@ -236,7 +236,7 @@ func Test_CreateServer(t *testing.T) {
BeforeFunc: core.BeforeFuncCombine(
createSbsVolume("Volume", 20),
),
Cmd: "scw instance server create image=ubuntu_jammy additional-volumes.0={{.Volume.ID}} stopped=true",
Cmd: testServerCommand("image=ubuntu_jammy additional-volumes.0={{.Volume.ID}} stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -258,7 +258,7 @@ func Test_CreateServer(t *testing.T) {
BeforeFunc: core.BeforeFuncCombine(
createSbsVolume("Volume", 20),
),
Cmd: "scw instance server create image=none root-volume={{.Volume.ID}} stopped=true",
Cmd: testServerCommand("image=none root-volume={{.Volume.ID}} stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -277,7 +277,7 @@ func Test_CreateServer(t *testing.T) {
instance.GetCommands(),
block.GetCommands(),
),
Cmd: "scw instance server create image=ubuntu_jammy root-volume=sbs:20GB stopped=true",
Cmd: testServerCommand("image=ubuntu_jammy root-volume=sbs:20GB stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -296,7 +296,7 @@ func Test_CreateServer(t *testing.T) {
instance.GetCommands(),
block.GetCommands(),
),
Cmd: "scw instance server create image=ubuntu_jammy root-volume=sbs:20GB:15000 stopped=true --debug",
Cmd: testServerCommand("image=ubuntu_jammy root-volume=sbs:20GB:15000 stopped=true --debug"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand Down Expand Up @@ -407,7 +407,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6 and dynamic ip", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic dynamic-ip-required=true ip=ipv6 -w", // IPv6 is created at runtime
Cmd: testServerCommand("image=ubuntu_bionic dynamic-ip-required=true ip=ipv6 -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -425,7 +425,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6 and ipv4", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=both -w", // IPv6 is created at runtime
Cmd: testServerCommand("image=ubuntu_bionic ip=both -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand Down
4 changes: 2 additions & 2 deletions internal/namespaces/instance/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
//
//nolint:unparam
func createServerBionic(metaKey string) core.BeforeFunc {
return core.ExecStoreBeforeCmd(metaKey, "scw instance server create type=DEV1-S stopped=true image=ubuntu-bionic")
return core.ExecStoreBeforeCmd(metaKey, testServerCommand("stopped=true image=ubuntu-bionic"))
}

//nolint:unparam
func createServer(metaKey string) core.BeforeFunc {
return core.ExecStoreBeforeCmd(metaKey, "scw instance server create stopped=true image=ubuntu-jammy")
return core.ExecStoreBeforeCmd(metaKey, testServerCommand("stopped=true image=ubuntu-jammy"))
}

// testServerCommand creates returns a create server command with the instance type and the given arguments
Expand Down

0 comments on commit da9d862

Please sign in to comment.