Skip to content

tests(instance): fix slow tests #4902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/namespaces/block/v1alpha1/custom_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func blockSnapshotCreateBuilder(c *core.Command) *core.Command {
resp := respI.(*block.Snapshot)

return block.NewAPI(core.ExtractClient(ctx)).WaitForSnapshot(&block.WaitForSnapshotRequest{
SnapshotID: resp.ID,
Zone: resp.Zone,
SnapshotID: resp.ID,
Zone: resp.Zone,
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down
5 changes: 3 additions & 2 deletions internal/namespaces/block/v1alpha1/custom_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ func blockVolumeCreateBuilder(c *core.Command) *core.Command {
resp := respI.(*block.Volume)

return block.NewAPI(core.ExtractClient(ctx)).WaitForVolume(&block.WaitForVolumeRequest{
VolumeID: resp.ID,
Zone: resp.Zone,
VolumeID: resp.ID,
Zone: resp.Zone,
RetryInterval: core.DefaultRetryInterval,
})
}

Expand Down
5 changes: 3 additions & 2 deletions internal/namespaces/function/v1beta1/custom_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ func DeployStepCreateNamespace(
})

namespace, err = api.WaitForNamespace(&function.WaitForNamespaceRequest{
NamespaceID: namespace.ID,
Region: namespace.Region,
NamespaceID: namespace.ID,
Region: namespace.Region,
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, fmt.Errorf("could not fetch created namespace: %w", err)
Expand Down
1 change: 1 addition & 0 deletions internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ func imageDeleteBuilder(c *core.Command) *core.Command {
SnapshotID: snapshot.ID,
Zone: args.Zone,
TerminalStatus: &terminalStatus,
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, err
Expand Down
4 changes: 0 additions & 4 deletions internal/namespaces/instance/v1/custom_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -45,7 +44,6 @@ func Test_IPAttach(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteServer("Server"),
),
DisableParallel: true,
}))
}

Expand All @@ -71,7 +69,6 @@ func Test_IPDetach(t *testing.T) {
deleteServer("Server"),
deleteIP("Ip"),
),
DisableParallel: true,
}))

t.Run("With IP", core.Test(&core.TestConfig{
Expand All @@ -95,6 +92,5 @@ func Test_IPDetach(t *testing.T) {
deleteServer("Server"),
deleteIP("Ip"),
),
DisableParallel: true,
}))
}
1 change: 1 addition & 0 deletions internal/namespaces/instance/v1/custom_server_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func serverTerminateCommand() *core.Command {
VolumeID: volume.ID,
Zone: volume.Zone,
TerminalStatus: &terminalStatus,
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
return nil, fmt.Errorf("failed to wait for block volume %s: %w", volume.ID, err)
Expand Down
17 changes: 4 additions & 13 deletions internal/namespaces/instance/v1/custom_server_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -77,7 +73,6 @@ func Test_ServerTerminate(t *testing.T) {
require.IsType(t, &scw.PermissionsDeniedError{}, err)
},
),
DisableParallel: true,
}))

t.Run("without block", core.Test(&core.TestConfig{
Expand All @@ -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{
Expand Down Expand Up @@ -141,10 +135,7 @@ func Test_ServerTerminate(t *testing.T) {
require.IsType(t, &scw.ResourceNotFoundError{}, err)
},
),
DisableParallel: true,
}))

interactive.IsInteractive = false
}

// These tests needs to be run in sequence
Expand Down
29 changes: 6 additions & 23 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,9 @@ func Test_CreateServer(t *testing.T) {

api := blockSDK.NewAPI(ctx.Client)
vol, err := api.WaitForVolume(&blockSDK.WaitForVolumeRequest{
VolumeID: rootVolume.ID,
Zone: rootVolume.Zone,
VolumeID: rootVolume.ID,
Zone: rootVolume.Zone,
RetryInterval: core.DefaultRetryInterval,
})
require.NoError(t, err)
assert.NotNil(t, vol.Specs)
Expand Down Expand Up @@ -635,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{
Expand All @@ -645,7 +645,6 @@ func Test_CreateServerErrors(t *testing.T) {
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
DisableParallel: true,
}))

////
Expand All @@ -658,7 +657,6 @@ func Test_CreateServerErrors(t *testing.T) {
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
DisableParallel: true,
}))

////
Expand All @@ -671,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{
Expand All @@ -683,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{
Expand All @@ -694,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{
Expand All @@ -706,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{
Expand All @@ -716,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{
Expand All @@ -729,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{
Expand All @@ -742,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{
Expand All @@ -753,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{
Expand All @@ -766,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{
Expand All @@ -784,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{
Expand All @@ -795,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{
Expand All @@ -807,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{
Expand All @@ -819,7 +805,6 @@ func Test_CreateServerErrors(t *testing.T) {
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
DisableParallel: true,
}))

////
Expand Down Expand Up @@ -905,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,
}))
}

Expand Down Expand Up @@ -939,6 +923,5 @@ func Test_AttachFilesystem(t *testing.T) {
"scw file filesystem delete {{ .FileSystem.ID }}",
),
),
DisableParallel: true,
}))
}
9 changes: 3 additions & 6 deletions internal/namespaces/instance/v1/custom_server_ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -54,7 +52,6 @@ func Test_ServerSSH(t *testing.T) {
core.TestCheckGolden(),
core.TestCheckExitCode(1),
),
AfterFunc: deleteServer("Server"),
DisableParallel: true,
AfterFunc: deleteServer("Server"),
}))
}
Loading
Loading