Skip to content

Commit

Permalink
tests(instance): update old tests and remove unsupported ones (#4220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Oct 23, 2024
1 parent a5b4e5d commit 0eb6229
Show file tree
Hide file tree
Showing 7 changed files with 2,212 additions and 5,564 deletions.
32 changes: 0 additions & 32 deletions internal/namespaces/instance/v1/custom_server_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,3 @@ func Test_ServerAction(t *testing.T) {
),
}))
}

func Test_ServerEnableRoutedIP(t *testing.T) {
t.Run("simple", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create zone=fr-par-3 type=PRO2-XXS image=ubuntu_jammy routed-ip-enabled=false ip=new --wait"),
Cmd: `scw instance server enable-routed-ip zone=fr-par-3 {{ .Server.ID }} --wait`,
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
storedServer := ctx.Meta["Server"].(*instanceSDK.Server)
api := instanceSDK.NewAPI(ctx.Client)
server, err := api.GetServer(&instanceSDK.GetServerRequest{
Zone: storedServer.Zone,
ServerID: storedServer.ID,
})
assert.Nil(t, err)
assert.Equal(t, scw.BoolPtr(true), server.Server.RoutedIPEnabled) //nolint: staticcheck // Field is deprecated but tested
ip, err := api.GetIP(&instanceSDK.GetIPRequest{
Zone: storedServer.Zone,
IP: storedServer.PublicIP.ID,
})
assert.Nil(t, err)
assert.Equal(t, instanceSDK.IPTypeRoutedIPv4, ip.IP.Type)
},
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: core.AfterFuncCombine(
core.ExecAfterCmd("scw instance server delete zone=fr-par-3 {{ .Server.ID }} force-shutdown=true with-ip=true with-volumes=local"),
),
}))
}
10 changes: 6 additions & 4 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/stretchr/testify/require"
)

// deleteServerAfterFunc deletes the created server and its attached volumes and IPs.
Expand Down Expand Up @@ -390,13 +391,14 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic routed-ip-enabled=false ipv6=true -w", // IPv6 is created at runtime
Cmd: "scw instance server create image=ubuntu_bionic ip=ipv6 dynamic-ip-required=false -w", // IPv6 is created at runtime
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
assert.NotNil(t, ctx.Result.(*instanceSDK.Server).IPv6)
assert.NotEmpty(t, ctx.Result.(*instanceSDK.Server).IPv6.Address)
require.NotNil(t, ctx.Result, "Server is nil")
server := ctx.Result.(*instanceSDK.Server)
assert.Len(t, server.PublicIPs, 1)
assert.Equal(t, instanceSDK.ServerIPIPFamilyInet6, server.PublicIPs[0].Family)
},
core.TestCheckExitCode(0),
),
Expand Down
7 changes: 4 additions & 3 deletions internal/namespaces/instance/v1/instance_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ func Test_GetServer(t *testing.T) {
func Test_CreateVolume(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance volume create name=test size=20G",
Cmd: "scw instance volume create name=test volume-type=b_ssd size=20G",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
require.NotNil(t, ctx.Result)
assert.Equal(t, "test", ctx.Result.(*instanceSDK.CreateVolumeResponse).Volume.Name)
},
core.TestCheckExitCode(0),
),
AfterFunc: core.ExecAfterCmd("scw instance volume delete {{ .CmdResult.Volume.ID }}"),
}))

t.Run("Bad size unit", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance volume create name=test size=20",
Cmd: "scw instance volume create name=test volume-type=b_ssd size=20",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand Down
Loading

0 comments on commit 0eb6229

Please sign in to comment.