From 31cf5699ac208265b62d6638bb6b15c940d37c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=AFla=20Marabese?= Date: Mon, 21 Jul 2025 19:31:51 +0200 Subject: [PATCH 1/4] remove Interactive and DisableParallel from Test_ServerTerminate --- .../instance/v1/custom_server_action_test.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_server_action_test.go b/internal/namespaces/instance/v1/custom_server_action_test.go index a3cb43a486..9e37470eaa 100644 --- a/internal/namespaces/instance/v1/custom_server_action_test.go +++ b/internal/namespaces/instance/v1/custom_server_action_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/scaleway/scaleway-cli/v2/core" - "github.com/scaleway/scaleway-cli/v2/internal/interactive" block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1" "github.com/scaleway/scaleway-cli/v2/internal/testhelpers" @@ -18,15 +17,13 @@ import ( // These tests needs to be run in sequence // since they are using the interactive print func Test_ServerTerminate(t *testing.T) { - interactive.IsInteractive = true - t.Run("without IP", core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: core.ExecStoreBeforeCmd( "Server", - testServerCommand("image=ubuntu-jammy ip=new -w"), + testServerCommand("image=ubuntu-jammy ip=new root-volume=local:10GB -w"), ), - Cmd: `scw instance server terminate {{ .Server.ID }} with-block=true`, + Cmd: `scw instance server terminate {{ .Server.ID }}`, Check: core.TestCheckCombine( core.TestCheckGolden(), core.TestCheckExitCode(0), @@ -48,16 +45,15 @@ func Test_ServerTerminate(t *testing.T) { AfterFunc: core.ExecAfterCmd( `scw instance ip delete {{ index .Server.PublicIP.ID }}`, ), - DisableParallel: true, })) t.Run("with IP", core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: core.ExecStoreBeforeCmd( "Server", - testServerCommand("image=ubuntu-jammy ip=new -w"), + testServerCommand("image=ubuntu-jammy ip=new root-volume=local:10GB -w"), ), - Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true with-block=true`, + Cmd: `scw instance server terminate {{ .Server.ID }} with-ip=true`, Check: core.TestCheckCombine( core.TestCheckGolden(), core.TestCheckExitCode(0), @@ -77,7 +73,6 @@ func Test_ServerTerminate(t *testing.T) { require.ErrorAs(t, err, new(*scw.ResourceNotFoundError)) }, ), - DisableParallel: true, })) t.Run("without block", core.Test(&core.TestConfig{ @@ -104,7 +99,6 @@ func Test_ServerTerminate(t *testing.T) { ), core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "0").ID }}`), ), - DisableParallel: true, })) t.Run("with block", core.Test(&core.TestConfig{ @@ -141,10 +135,7 @@ func Test_ServerTerminate(t *testing.T) { require.ErrorAs(t, err, new(*scw.ResourceNotFoundError)) }, ), - DisableParallel: true, })) - - interactive.IsInteractive = false } // These tests needs to be run in sequence From c7854e81a3e1c9cb80fa62f951e3f67544e02ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=AFla=20Marabese?= Date: Mon, 21 Jul 2025 21:16:05 +0200 Subject: [PATCH 2/4] remove remaining DisableParallel --- .../namespaces/instance/v1/custom_ip_test.go | 4 ---- .../instance/v1/custom_server_create_test.go | 24 +++---------------- .../instance/v1/custom_server_ssh_test.go | 9 +++---- .../instance/v1/custom_server_test.go | 19 ++++----------- 4 files changed, 10 insertions(+), 46 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_ip_test.go b/internal/namespaces/instance/v1/custom_ip_test.go index bb6e7dacab..7d9d238f20 100644 --- a/internal/namespaces/instance/v1/custom_ip_test.go +++ b/internal/namespaces/instance/v1/custom_ip_test.go @@ -25,7 +25,6 @@ func Test_IPAttach(t *testing.T) { AfterFunc: core.AfterFuncCombine( deleteServer("Server"), ), - DisableParallel: true, })) t.Run("With IP", core.Test(&core.TestConfig{ @@ -45,7 +44,6 @@ func Test_IPAttach(t *testing.T) { AfterFunc: core.AfterFuncCombine( deleteServer("Server"), ), - DisableParallel: true, })) } @@ -71,7 +69,6 @@ func Test_IPDetach(t *testing.T) { deleteServer("Server"), deleteIP("Ip"), ), - DisableParallel: true, })) t.Run("With IP", core.Test(&core.TestConfig{ @@ -95,6 +92,5 @@ func Test_IPDetach(t *testing.T) { deleteServer("Server"), deleteIP("Ip"), ), - DisableParallel: true, })) } diff --git a/internal/namespaces/instance/v1/custom_server_create_test.go b/internal/namespaces/instance/v1/custom_server_create_test.go index 700947b495..b2e520e6ad 100644 --- a/internal/namespaces/instance/v1/custom_server_create_test.go +++ b/internal/namespaces/instance/v1/custom_server_create_test.go @@ -636,7 +636,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid image UUID", core.Test(&core.TestConfig{ @@ -646,7 +645,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) //// @@ -659,7 +657,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) //// @@ -672,7 +669,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid total local volumes size: too low 2", core.Test(&core.TestConfig{ @@ -684,7 +680,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid total local volumes size: too low 3", core.Test(&core.TestConfig{ @@ -695,7 +690,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid total local volumes size: too high 1", core.Test(&core.TestConfig{ @@ -707,7 +701,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid total local volumes size: too high 2", core.Test(&core.TestConfig{ @@ -717,7 +710,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid total local volumes size: too high 3", core.Test(&core.TestConfig{ @@ -730,8 +722,7 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteVolume("Volume"), - DisableParallel: true, + AfterFunc: deleteVolume("Volume"), })) t.Run("Error: invalid root volume size", core.Test(&core.TestConfig{ @@ -743,7 +734,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: disallow existing root volume ID", core.Test(&core.TestConfig{ @@ -754,8 +744,7 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteVolume("Volume"), - DisableParallel: true, + AfterFunc: deleteVolume("Volume"), })) t.Run("Error: invalid root volume ID", core.Test(&core.TestConfig{ @@ -767,7 +756,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: already attached additional volume ID", core.Test(&core.TestConfig{ @@ -785,8 +773,7 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) t.Run("Error: invalid root volume format", core.Test(&core.TestConfig{ @@ -796,7 +783,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid root volume snapshot ID", core.Test(&core.TestConfig{ @@ -808,7 +794,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) t.Run("Error: invalid additional volume snapshot ID", core.Test(&core.TestConfig{ @@ -820,7 +805,6 @@ func Test_CreateServerErrors(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - DisableParallel: true, })) //// @@ -906,7 +890,6 @@ func Test_CreateServerScratchStorage(t *testing.T) { AfterFunc: core.ExecAfterCmd( "scw instance server delete {{ .CmdResult.ID }} zone=fr-par-2 with-volumes=all with-ip=true force-shutdown=true", ), - DisableParallel: true, })) } @@ -940,6 +923,5 @@ func Test_AttachFilesystem(t *testing.T) { "scw file filesystem delete {{ .FileSystem.ID }}", ), ), - DisableParallel: true, })) } diff --git a/internal/namespaces/instance/v1/custom_server_ssh_test.go b/internal/namespaces/instance/v1/custom_server_ssh_test.go index 9fa8c54827..b3d57c76ee 100644 --- a/internal/namespaces/instance/v1/custom_server_ssh_test.go +++ b/internal/namespaces/instance/v1/custom_server_ssh_test.go @@ -23,8 +23,7 @@ func Test_ServerSSH(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) t.Run("With-Exit-Code", core.Test(&core.TestConfig{ @@ -42,8 +41,7 @@ func Test_ServerSSH(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(130), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) t.Run("Stopped server", core.Test(&core.TestConfig{ @@ -54,7 +52,6 @@ func Test_ServerSSH(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) } diff --git a/internal/namespaces/instance/v1/custom_server_test.go b/internal/namespaces/instance/v1/custom_server_test.go index 2c95cc8099..e46a93b1c4 100644 --- a/internal/namespaces/instance/v1/custom_server_test.go +++ b/internal/namespaces/instance/v1/custom_server_test.go @@ -43,8 +43,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { testAttachVolumeServerSBSVolumeSize("0", 10), testAttachVolumeServerSBSVolumeSize("1", 10), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) t.Run("simple local volume", core.Test(&core.TestConfig{ @@ -70,8 +69,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { }, testAttachVolumeServerSBSVolumeSize("0", 10), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) t.Run("invalid volume UUID", core.Test(&core.TestConfig{ @@ -82,8 +80,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) }) t.Run("Detach", func(t *testing.T) { @@ -116,7 +113,6 @@ func Test_ServerVolumeUpdate(t *testing.T) { core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`), deleteServer("Server"), ), - DisableParallel: true, })) t.Run("invalid volume UUID", core.Test(&core.TestConfig{ @@ -127,8 +123,7 @@ func Test_ServerVolumeUpdate(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(1), ), - AfterFunc: deleteServer("Server"), - DisableParallel: true, + AfterFunc: deleteServer("Server"), })) }) } @@ -339,7 +334,6 @@ func Test_ServerDelete(t *testing.T) { core.TestCheckGolden(), core.TestCheckExitCode(0), ), - DisableParallel: true, })) t.Run("only block volumes", core.Test(&core.TestConfig{ @@ -356,7 +350,6 @@ func Test_ServerDelete(t *testing.T) { AfterFunc: core.ExecAfterCmd( `scw instance volume delete {{ (index .Server.Volumes "0").ID }}`, ), - DisableParallel: true, })) t.Run("only local volumes", core.Test(&core.TestConfig{ @@ -379,7 +372,6 @@ func Test_ServerDelete(t *testing.T) { ), core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`), ), - DisableParallel: true, })) t.Run("with none volumes", core.Test(&core.TestConfig{ @@ -409,7 +401,6 @@ func Test_ServerDelete(t *testing.T) { core.ExecAfterCmd(`scw instance volume delete {{ (index .Server.Volumes "0").ID }}`), core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`), ), - DisableParallel: true, })) t.Run("with sbs volumes", func(t *testing.T) { @@ -447,7 +438,6 @@ func Test_ServerDelete(t *testing.T) { assert.Error(t, err, "%v", resp) }, ), - DisableParallel: true, }) }) @@ -474,7 +464,6 @@ func Test_ServerDelete(t *testing.T) { } }, ), - DisableParallel: true, })) interactive.IsInteractive = false From 9f0d8d422c2310d7c3f4e19f9fcf91dff4703dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=AFla=20Marabese?= Date: Tue, 22 Jul 2025 00:10:43 +0200 Subject: [PATCH 3/4] remove interactive in Test_ServerDelete --- internal/namespaces/instance/v1/custom_server_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_server_test.go b/internal/namespaces/instance/v1/custom_server_test.go index e46a93b1c4..853d098623 100644 --- a/internal/namespaces/instance/v1/custom_server_test.go +++ b/internal/namespaces/instance/v1/custom_server_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/scaleway/scaleway-cli/v2/core" - "github.com/scaleway/scaleway-cli/v2/internal/interactive" block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1" "github.com/scaleway/scaleway-cli/v2/internal/testhelpers" @@ -321,8 +320,6 @@ func Test_ServerUpdateCustom(t *testing.T) { // These tests needs to be run in sequence // since they are using the interactive print func Test_ServerDelete(t *testing.T) { - interactive.IsInteractive = true - t.Run("with all volumes", core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: core.ExecStoreBeforeCmd( @@ -465,6 +462,4 @@ func Test_ServerDelete(t *testing.T) { }, ), })) - - interactive.IsInteractive = false } From c174727ba05ca190357aff6ab9139623e3e4b1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=AFla=20Marabese?= Date: Tue, 22 Jul 2025 00:12:14 +0200 Subject: [PATCH 4/4] gather all server update tests in Test_ServerUpdate --- .../instance/v1/custom_server_test.go | 222 ++--------- .../instance/v1/instance_cli_test.go | 375 +++++++++++++----- 2 files changed, 303 insertions(+), 294 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_server_test.go b/internal/namespaces/instance/v1/custom_server_test.go index 853d098623..d71de01912 100644 --- a/internal/namespaces/instance/v1/custom_server_test.go +++ b/internal/namespaces/instance/v1/custom_server_test.go @@ -127,195 +127,45 @@ func Test_ServerVolumeUpdate(t *testing.T) { }) } -func Test_ServerUpdateCustom(t *testing.T) { - // IP cases. - t.Run("Try to remove ip from server without ip", core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: createServer("Server"), - Cmd: "scw instance server update {{ .Server.ID }} ip=none", - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result) - assert.Equal(t, (*instanceSDK.ServerIP)(nil), resp.Server.PublicIP) - }, - core.TestCheckExitCode(0), - ), - AfterFunc: deleteServer("Server"), - })) - - t.Run("Update server ip from server without ip", core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createServer("Server"), - createIP("IP"), - ), - Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP.Address }}", - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - ip := testhelpers.MapValue[*instanceSDK.IP](t, ctx.Meta, "IP") - resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result) - - assert.NotNil(t, resp.Server) - assert.NotNil(t, resp.Server.PublicIP) - assert.Equal(t, ip.Address, resp.Server.PublicIP.Address) - }, - core.TestCheckExitCode(0), - ), - AfterFunc: deleteServer("Server"), - })) - - t.Run("Update server ip from server with ip", core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createServer("Server"), - createIP("IP1"), - createIP("IP2"), - - // Attach IP1 to Server. - core.ExecStoreBeforeCmd( - "UpdatedServer", - "scw instance server update {{ .Server.ID }} ip={{ .IP1.Address }}", - ), - ), - Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP2.Address }}", - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - // Test that the Server WAS attached to IP1. - assert.Equal( - t, - ctx.Meta["IP1"].(*instanceSDK.IP).Address, - ctx.Meta["UpdatedServer"].(*instance.ServerWithWarningsResponse).Server.PublicIP.Address, - ) - // Test that the Server IS attached to IP2. - assert.Equal(t, - ctx.Meta["IP2"].(*instanceSDK.IP).Address, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PublicIP.Address) - }, - core.TestCheckExitCode(0), - ), - AfterFunc: core.AfterFuncCombine( - deleteServer("Server"), - deleteIP("IP1"), - ), - })) - - // Placement group cases. - t.Run( - "Update server placement-group-id from server with placement-group-id", - core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createPlacementGroup("PlacementGroup1"), - createPlacementGroup("PlacementGroup2"), - core.ExecStoreBeforeCmd( - "Server", - testServerCommand( - "stopped=true image=ubuntu-jammy placement-group-id={{ .PlacementGroup1.ID }}", - ), - ), - ), - Cmd: "scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}", - Check: core.TestCheckCombine( - core.TestCheckExitCode(0), - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - assert.Equal(t, - ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID) - }, - ), - AfterFunc: core.AfterFuncCombine( - deleteServer("Server"), - deletePlacementGroup("PlacementGroup1"), - deletePlacementGroup("PlacementGroup2"), - ), - }), - ) +//func Test_ServerUpdateCustom(t *testing.T) { +// Placement group cases. +//t.Run( +// "Update server placement-group-id from server with placement-group-id", +// core.Test(&core.TestConfig{ +// Commands: instance.GetCommands(), +// BeforeFunc: core.BeforeFuncCombine( +// createPlacementGroup("PlacementGroup1"), +// createPlacementGroup("PlacementGroup2"), +// core.ExecStoreBeforeCmd( +// "Server", +// testServerCommand( +// "stopped=true image=ubuntu-jammy placement-group-id={{ .PlacementGroup1.ID }}", +// ), +// ), +// ), +// Cmd: "scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}", +// Check: core.TestCheckCombine( +// core.TestCheckExitCode(0), +// func(t *testing.T, ctx *core.CheckFuncCtx) { +// t.Helper() +// assert.Equal(t, +// ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, +// ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID) +// }, +// ), +// AfterFunc: core.AfterFuncCombine( +// deleteServer("Server"), +// deletePlacementGroup("PlacementGroup1"), +// deletePlacementGroup("PlacementGroup2"), +// ), +// }), +//) - // Security group cases. - t.Run( - "Update server security-group-id from server with security-group-id", - core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createSecurityGroup("SecurityGroup1"), - createSecurityGroup("SecurityGroup2"), - core.ExecStoreBeforeCmd( - "Server", - testServerCommand( - "stopped=true image=ubuntu-jammy security-group-id={{ .SecurityGroup1.ID }}", - ), - ), - ), - Cmd: "scw instance server update {{ .Server.ID }} security-group-id={{ .SecurityGroup2.ID }}", - Check: core.TestCheckCombine( - core.TestCheckExitCode(0), - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - assert.Equal(t, - ctx.Meta["SecurityGroup2"].(*instanceSDK.SecurityGroup).ID, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.SecurityGroup.ID) - }, - ), - AfterFunc: core.AfterFuncCombine( - deleteServer("Server"), - deleteSecurityGroup("SecurityGroup1"), - deleteSecurityGroup("SecurityGroup2"), - ), - }), - ) +// Security group cases. - // Volumes cases. - t.Run("Volumes", func(t *testing.T) { - t.Run("valid simple block volume", core.Test(&core.TestConfig{ - Commands: core.NewCommandsMerge( - block.GetCommands(), - instance.GetCommands(), - ), - BeforeFunc: core.BeforeFuncCombine( - createServer("Server"), - createSbsVolume("Volume", 10), - ), - Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`, - Check: core.TestCheckCombine( - testServerUpdateServerSBSVolumeSize("0", 10), - testServerUpdateServerSBSVolumeSize("1", 10), - ), - AfterFunc: deleteServer("Server"), - })) +// Volumes cases. - t.Run("detach all volumes", core.Test(&core.TestConfig{ - Commands: core.NewCommandsMerge( - block.GetCommands(), - instance.GetCommands(), - ), - BeforeFunc: core.ExecStoreBeforeCmd( - "Server", - testServerCommand("stopped=true image=ubuntu-jammy additional-volumes.0=block:10G"), - ), - Cmd: `scw instance server update {{ .Server.ID }} volume-ids=none`, - Check: func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - require.NoError(t, ctx.Err) - assert.Empty(t, ctx.Result.(*instance.ServerWithWarningsResponse).Server.Volumes) - }, - AfterFunc: core.AfterFuncCombine( - core.ExecAfterCmd( - `scw block volume wait terminal-status=available {{ (index .Server.Volumes "0").ID }}`, - ), - core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "0").ID }}`), - core.ExecAfterCmd( - `scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}`, - ), - core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`), - deleteServer("Server"), - ), - })) - }) -} +//} // These tests needs to be run in sequence // since they are using the interactive print diff --git a/internal/namespaces/instance/v1/instance_cli_test.go b/internal/namespaces/instance/v1/instance_cli_test.go index ea6328a559..f412901375 100644 --- a/internal/namespaces/instance/v1/instance_cli_test.go +++ b/internal/namespaces/instance/v1/instance_cli_test.go @@ -6,6 +6,7 @@ import ( "github.com/scaleway/scaleway-cli/v2/core" block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1" "github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1" + "github.com/scaleway/scaleway-cli/v2/internal/testhelpers" instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -74,40 +75,98 @@ func Test_ServerUpdate(t *testing.T) { AfterFunc: deleteServer("Server"), })) - t.Run("No initial placement group & placement-group-id=none", core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: createServer("Server"), - Cmd: "scw instance server update {{ .Server.ID }} placement-group-id=none", - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - require.NoError(t, ctx.Err) - assert.Nil( - t, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup, - ) - }, - core.TestCheckExitCode(0), - ), - AfterFunc: deleteServer("Server"), - })) + t.Run("Placement groups", func(t *testing.T) { - t.Run( - `No initial placement group & placement-group-id=`, - core.Test(&core.TestConfig{ + t.Run("No initial placement group & placement-group-id=none", core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: createServer("Server"), + Cmd: "scw instance server update {{ .Server.ID }} placement-group-id=none", + Check: core.TestCheckCombine( + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + require.NoError(t, ctx.Err) + assert.Nil( + t, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup, + ) + }, + core.TestCheckExitCode(0), + ), + AfterFunc: deleteServer("Server"), + })) + + t.Run( + `No initial placement group & placement-group-id=`, + core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + createPlacementGroup("PlacementGroup"), + createServer("Server"), + ), + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, + Check: core.TestCheckCombine( + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + require.NoError(t, ctx.Err) + assert.Equal(t, + ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, + ) + }, + core.TestCheckExitCode(0), + ), + AfterFunc: core.AfterFuncCombine( + deleteServer("Server"), + deletePlacementGroup("PlacementGroup"), + ), + }), + ) + + t.Run( + `No initial placement group & placement-group-id=`, + core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: createServer("Server"), + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=11111111-1111-1111-1111-111111111111`, + Check: core.TestCheckCombine( + core.TestCheckExitCode(1), + core.TestCheckGolden(), + ), + AfterFunc: deleteServer("Server"), + }), + ) + + t.Run( + `No initial placement group & placement-group-id=`, + core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: createServer("Server"), + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=1111111`, + Check: core.TestCheckCombine( + core.TestCheckExitCode(1), + core.TestCheckGolden(), + ), + AfterFunc: deleteServer("Server"), + }), + ) + + t.Run(`Initial placement group & placement-group-id=none`, core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: core.BeforeFuncCombine( createPlacementGroup("PlacementGroup"), - createServer("Server"), + core.ExecStoreBeforeCmd( + "Server", + testServerCommand("placement-group-id={{ .PlacementGroup.ID }} stopped=true"), + ), ), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=none`, Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { t.Helper() require.NoError(t, ctx.Err) - assert.Equal(t, - ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, + assert.Nil( + t, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup, ) }, core.TestCheckExitCode(0), @@ -116,122 +175,222 @@ func Test_ServerUpdate(t *testing.T) { deleteServer("Server"), deletePlacementGroup("PlacementGroup"), ), - }), - ) + })) - t.Run( - `No initial placement group & placement-group-id=`, - core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: createServer("Server"), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=11111111-1111-1111-1111-111111111111`, + t.Run( + `Initial placement group & placement-group-id=`, + core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + createPlacementGroup("PlacementGroup"), + core.ExecStoreBeforeCmd( + "Server", + testServerCommand("placement-group-id={{ .PlacementGroup.ID }} stopped=true"), + ), + ), + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, + Check: core.TestCheckCombine( + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + require.NoError(t, ctx.Err) + assert.Equal(t, + ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, + ) + }, + core.TestCheckExitCode(0), + ), + AfterFunc: core.AfterFuncCombine( + deleteServer("Server"), + deletePlacementGroup("PlacementGroup"), + ), + }), + ) + + t.Run(`Initial placement group & placement-group-id=`, core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + createPlacementGroup("PlacementGroup1"), + createPlacementGroup("PlacementGroup2"), + core.ExecStoreBeforeCmd( + "Server", + testServerCommand("placement-group-id={{ .PlacementGroup1.ID }} stopped=true"), + ), + ), + Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}`, Check: core.TestCheckCombine( - core.TestCheckExitCode(1), - core.TestCheckGolden(), + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + require.NoError(t, ctx.Err) + assert.Equal(t, + ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, + ) + }, + core.TestCheckExitCode(0), ), - AfterFunc: deleteServer("Server"), - }), - ) + AfterFunc: core.AfterFuncCombine( + deleteServer("Server"), + deletePlacementGroup("PlacementGroup1"), + deletePlacementGroup("PlacementGroup2"), + ), + })) + }) - t.Run( - `No initial placement group & placement-group-id=`, - core.Test(&core.TestConfig{ + t.Run("IP", func(t *testing.T) { + t.Run("Try to remove ip from server without ip", core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: createServer("Server"), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=1111111`, + Cmd: "scw instance server update {{ .Server.ID }} ip=none", Check: core.TestCheckCombine( - core.TestCheckExitCode(1), - core.TestCheckGolden(), + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result) + assert.Equal(t, (*instanceSDK.ServerIP)(nil), resp.Server.PublicIP) + }, + core.TestCheckExitCode(0), ), AfterFunc: deleteServer("Server"), - }), - ) + })) - t.Run(`Initial placement group & placement-group-id=none`, core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createPlacementGroup("PlacementGroup"), - core.ExecStoreBeforeCmd( - "Server", - testServerCommand("placement-group-id={{ .PlacementGroup.ID }} stopped=true"), + t.Run("Update server ip from server without ip", core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + createServer("Server"), + createIP("IP"), ), - ), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id=none`, - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { - t.Helper() - require.NoError(t, ctx.Err) - assert.Nil( - t, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup, - ) - }, - core.TestCheckExitCode(0), - ), - AfterFunc: core.AfterFuncCombine( - deleteServer("Server"), - deletePlacementGroup("PlacementGroup"), - ), - })) + Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP.Address }}", + Check: core.TestCheckCombine( + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + ip := testhelpers.MapValue[*instanceSDK.IP](t, ctx.Meta, "IP") + resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result) + + assert.NotNil(t, resp.Server) + assert.NotNil(t, resp.Server.PublicIP) + assert.Equal(t, ip.Address, resp.Server.PublicIP.Address) + }, + core.TestCheckExitCode(0), + ), + AfterFunc: deleteServer("Server"), + })) - t.Run( - `Initial placement group & placement-group-id=`, - core.Test(&core.TestConfig{ + t.Run("Update server ip from server with ip", core.Test(&core.TestConfig{ Commands: instance.GetCommands(), BeforeFunc: core.BeforeFuncCombine( - createPlacementGroup("PlacementGroup"), + createServer("Server"), + createIP("IP1"), + createIP("IP2"), + + // Attach IP1 to Server. core.ExecStoreBeforeCmd( - "Server", - testServerCommand("placement-group-id={{ .PlacementGroup.ID }} stopped=true"), + "UpdatedServer", + "scw instance server update {{ .Server.ID }} ip={{ .IP1.Address }}", ), ), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup.ID }}`, + Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP2.Address }}", Check: core.TestCheckCombine( func(t *testing.T, ctx *core.CheckFuncCtx) { t.Helper() - require.NoError(t, ctx.Err) - assert.Equal(t, - ctx.Meta["PlacementGroup"].(*instanceSDK.PlacementGroup).ID, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, + // Test that the Server WAS attached to IP1. + assert.Equal( + t, + ctx.Meta["IP1"].(*instanceSDK.IP).Address, + ctx.Meta["UpdatedServer"].(*instance.ServerWithWarningsResponse).Server.PublicIP.Address, ) + // Test that the Server IS attached to IP2. + assert.Equal(t, + ctx.Meta["IP2"].(*instanceSDK.IP).Address, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.PublicIP.Address) }, core.TestCheckExitCode(0), ), AfterFunc: core.AfterFuncCombine( deleteServer("Server"), - deletePlacementGroup("PlacementGroup"), + deleteIP("IP1"), ), - }), - ) + })) + }) - t.Run(`Initial placement group & placement-group-id=`, core.Test(&core.TestConfig{ - Commands: instance.GetCommands(), - BeforeFunc: core.BeforeFuncCombine( - createPlacementGroup("PlacementGroup1"), - createPlacementGroup("PlacementGroup2"), - core.ExecStoreBeforeCmd( + t.Run("Security Groups", func(t *testing.T) { + t.Run("Update server security-group-id from server with security-group-id", + core.Test(&core.TestConfig{ + Commands: instance.GetCommands(), + BeforeFunc: core.BeforeFuncCombine( + createSecurityGroup("SecurityGroup1"), + createSecurityGroup("SecurityGroup2"), + core.ExecStoreBeforeCmd( + "Server", + testServerCommand( + "stopped=true image=ubuntu-jammy security-group-id={{ .SecurityGroup1.ID }}", + ), + ), + ), + Cmd: "scw instance server update {{ .Server.ID }} security-group-id={{ .SecurityGroup2.ID }}", + Check: core.TestCheckCombine( + core.TestCheckExitCode(0), + func(t *testing.T, ctx *core.CheckFuncCtx) { + t.Helper() + assert.Equal(t, + ctx.Meta["SecurityGroup2"].(*instanceSDK.SecurityGroup).ID, + ctx.Result.(*instance.ServerWithWarningsResponse).Server.SecurityGroup.ID) + }, + ), + AfterFunc: core.AfterFuncCombine( + deleteServer("Server"), + deleteSecurityGroup("SecurityGroup1"), + deleteSecurityGroup("SecurityGroup2"), + ), + }), + ) + }) + + t.Run("Volumes", func(t *testing.T) { + t.Run("valid simple block volume", core.Test(&core.TestConfig{ + Commands: core.NewCommandsMerge( + block.GetCommands(), + instance.GetCommands(), + ), + BeforeFunc: core.BeforeFuncCombine( + createServer("Server"), + createSbsVolume("Volume", 10), + ), + Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`, + Check: core.TestCheckCombine( + testServerUpdateServerSBSVolumeSize("0", 10), + testServerUpdateServerSBSVolumeSize("1", 10), + ), + AfterFunc: deleteServer("Server"), + })) + + t.Run("detach all volumes", core.Test(&core.TestConfig{ + Commands: core.NewCommandsMerge( + block.GetCommands(), + instance.GetCommands(), + ), + BeforeFunc: core.ExecStoreBeforeCmd( "Server", - testServerCommand("placement-group-id={{ .PlacementGroup1.ID }} stopped=true"), + testServerCommand("stopped=true image=ubuntu-jammy additional-volumes.0=block:10G"), ), - ), - Cmd: `scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}`, - Check: core.TestCheckCombine( - func(t *testing.T, ctx *core.CheckFuncCtx) { + Cmd: `scw instance server update {{ .Server.ID }} volume-ids=none`, + Check: func(t *testing.T, ctx *core.CheckFuncCtx) { t.Helper() require.NoError(t, ctx.Err) - assert.Equal(t, - ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID, - ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID, - ) + assert.Empty(t, ctx.Result.(*instance.ServerWithWarningsResponse).Server.Volumes) }, - core.TestCheckExitCode(0), - ), - AfterFunc: core.AfterFuncCombine( - deleteServer("Server"), - deletePlacementGroup("PlacementGroup1"), - deletePlacementGroup("PlacementGroup2"), - ), - })) + AfterFunc: core.AfterFuncCombine( + core.ExecAfterCmd( + `scw block volume wait terminal-status=available {{ (index .Server.Volumes "0").ID }}`, + ), + core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "0").ID }}`), + core.ExecAfterCmd( + `scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}`, + ), + core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`), + deleteServer("Server"), + ), + })) + }) } // Snapshot