Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Feb 20, 2023
1 parent e3c5342 commit a1598f6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 48 deletions.
62 changes: 31 additions & 31 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
t.Run("Default", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -47,7 +47,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("With name", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic name=yo stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic name=yo stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, "yo", ctx.Result.(*instance.Server).Name)
Expand All @@ -59,7 +59,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("With start", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic -w",
Cmd: testServerCommand("image=ubuntu_bionic -w"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, instance.ServerStateRunning, ctx.Result.(*instance.Server).State)
Expand All @@ -71,7 +71,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("With bootscript", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic bootscript-id=eb760e3c-30d8-49a3-b3ad-ad10c3aa440b stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic bootscript-id=eb760e3c-30d8-49a3-b3ad-ad10c3aa440b stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
//nolint: staticcheck // Bootscript is deprecated
Expand All @@ -85,7 +85,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("Image UUID", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=f974feac-abae-4365-b988-8ec7d1cec10d stopped=true",
Cmd: testServerCommand("image=f974feac-abae-4365-b988-8ec7d1cec10d stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, "Ubuntu Bionic Beaver", ctx.Result.(*instance.Server).Image.Name)
Expand All @@ -97,7 +97,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("Tags", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic tags.0=prod tags.1=blue stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic tags.0=prod tags.1=blue stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, "prod", ctx.Result.(*instance.Server).Tags[0])
Expand All @@ -115,7 +115,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("Volumes", func(t *testing.T) {
t.Run("valid single local volume", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:20GB stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=local:20GB stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, 20*scw.GB, ctx.Result.(*instance.Server).Volumes["0"].Size)
Expand All @@ -127,7 +127,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("valid double local volumes", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:10GB additional-volumes.0=l:10G stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=local:10GB additional-volumes.0=l:10G stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, 10*scw.GB, ctx.Result.(*instance.Server).Volumes["0"].Size)
Expand All @@ -140,7 +140,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("valid additional block volumes", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.Equal(t, 1*scw.GB, ctx.Result.(*instance.Server).Volumes["1"].Size)
Expand All @@ -158,7 +158,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("IPs", func(t *testing.T) {
t.Run("explicit new IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=new stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic ip=new stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.NotEmpty(t, ctx.Result.(*instance.Server).PublicIP.Address)
Expand All @@ -171,7 +171,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("run with dynamic IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=dynamic -w", // dynamic IP is created at runtime
Cmd: testServerCommand("image=ubuntu_bionic ip=dynamic -w"), // dynamic IP is created at runtime
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.NoError(t, ctx.Err)
Expand All @@ -186,7 +186,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("existing IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: createIP("IP"),
Cmd: "scw instance server create image=ubuntu_bionic ip={{ .IP.Address }} stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic ip={{ .IP.Address }} stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.NotEmpty(t, ctx.Result.(*instance.Server).PublicIP.Address)
Expand All @@ -200,7 +200,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("existing IP ID", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: createIP("IP"),
Cmd: "scw instance server create image=ubuntu_bionic ip={{ .IP.ID }} stopped=true",
Cmd: testServerCommand("image=ubuntu_bionic ip={{ .IP.ID }} stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.NotEmpty(t, ctx.Result.(*instance.Server).PublicIP.Address)
Expand All @@ -213,7 +213,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ipv6=true -w", // IPv6 is created at runtime
Cmd: testServerCommand("image=ubuntu_bionic ipv6=true -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
assert.NotEmpty(t, ctx.Result.(*instance.Server).IPv6.Address)
Expand All @@ -234,7 +234,7 @@ func Test_CreateServerErrors(t *testing.T) {
////
t.Run("Error: invalid image label", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=macos",
Cmd: testServerCommand("image=macos"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -244,7 +244,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid image UUID", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=7a892c1a-bbdc-491f-9974-4008e3708664",
Cmd: testServerCommand("image=7a892c1a-bbdc-491f-9974-4008e3708664"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -270,7 +270,7 @@ func Test_CreateServerErrors(t *testing.T) {
////
t.Run("Error: invalid total local volumes size: too low 1", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=l:10GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=l:10GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -280,7 +280,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid total local volumes size: too low 2", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=l:10GB additional-volumes.0=block:10GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=l:10GB additional-volumes.0=block:10GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -290,7 +290,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid total local volumes size: too low 3", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=block:20GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=block:20GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -300,7 +300,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid total local volumes size: too high 1", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:10GB additional-volumes.0=local:20GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=local:10GB additional-volumes.0=local:20GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -310,7 +310,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid total local volumes size: too high 2", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic additional-volumes.0=local:10GB",
Cmd: testServerCommand("image=ubuntu_bionic additional-volumes.0=local:10GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -321,7 +321,7 @@ func Test_CreateServerErrors(t *testing.T) {
t.Run("Error: invalid total local volumes size: too high 3", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: createVolume("Volume", 20, instance.VolumeVolumeTypeLSSD),
Cmd: "scw instance server create image=ubuntu_bionic root-volume={{ .Volume.ID }} additional-volumes.0=local:10GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume={{ .Volume.ID }} additional-volumes.0=local:10GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -332,7 +332,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid root volume size", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=local:2GB additional-volumes.0=local:18GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=local:2GB additional-volumes.0=local:18GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -343,7 +343,7 @@ func Test_CreateServerErrors(t *testing.T) {
t.Run("Error: disallow existing root volume ID", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: createVolume("Volume", 20, instance.VolumeVolumeTypeLSSD),
Cmd: "scw instance server create image=ubuntu_bionic root-volume={{ .Volume.ID }}",
Cmd: testServerCommand("image=ubuntu_bionic root-volume={{ .Volume.ID }}"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -354,7 +354,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid root volume ID", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=29da9ad9-e759-4a56-82c8-f0607f93055c",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=29da9ad9-e759-4a56-82c8-f0607f93055c"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -364,8 +364,8 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: already attached additional volume ID", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.ExecStoreBeforeCmd("Server", "scw instance server create name=cli-test image=ubuntu_bionic root-volume=l:10G additional-volumes.0=l:10G stopped=true"),
Cmd: `scw instance server create image=ubuntu_bionic root-volume=l:10G additional-volumes.0={{ (index .Server.Volumes "1").ID }} stopped=true`,
BeforeFunc: core.ExecStoreBeforeCmd("Server", testServerCommand("name=cli-test image=ubuntu_bionic root-volume=l:10G additional-volumes.0=l:10G stopped=true")),
Cmd: testServerCommand(`image=ubuntu_bionic root-volume=l:10G additional-volumes.0={{ (index .Server.Volumes "1").ID }} stopped=true`),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -376,7 +376,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid root volume format", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic root-volume=20GB",
Cmd: testServerCommand("image=ubuntu_bionic root-volume=20GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -389,7 +389,7 @@ func Test_CreateServerErrors(t *testing.T) {
////
t.Run("Error: not found ip ID", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=23165951-13fd-4a3b-84ed-22c2e96658f2",
Cmd: testServerCommand("image=ubuntu_bionic ip=23165951-13fd-4a3b-84ed-22c2e96658f2"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -398,7 +398,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: forbidden IP", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=51.15.242.82",
Cmd: testServerCommand("image=ubuntu_bionic ip=51.15.242.82"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand All @@ -407,7 +407,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid ip", core.Test(&core.TestConfig{
Commands: GetCommands(),
Cmd: "scw instance server create image=ubuntu_bionic ip=yo",
Cmd: testServerCommand("image=ubuntu_bionic ip=yo"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand Down
Loading

0 comments on commit a1598f6

Please sign in to comment.