Skip to content

Commit

Permalink
update double snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed Jan 23, 2025
1 parent df91970 commit 839d2d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
24 changes: 10 additions & 14 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,24 @@ func Test_CreateServer(t *testing.T) {
}))

t.Run("valid double snapshot", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Commands: core.NewCommandsMerge(
instance.GetCommands(),
block.GetCommands(),
),
BeforeFunc: core.BeforeFuncCombine(
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 }}`),
core.ExecStoreBeforeCmd("Server", testServerCommand("image=ubuntu_jammy root-volume=block:20GB stopped=true")),
core.ExecStoreBeforeCmd("Snapshot", `scw block snapshot create volume-id={{ (index .Server.Volumes "0").ID }} -w`),
),
Cmd: testServerCommand("image=ubuntu_bionic root-volume=block:{{ .Snapshot.Snapshot.ID }} additional-volumes.0=local:{{ .Snapshot.Snapshot.ID }} stopped=true"),
Cmd: testServerCommand("image=ubuntu_jammy root-volume=block:{{ .Snapshot.ID }} additional-volumes.0=block:{{ .Snapshot.ID }} stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
server := testhelpers.Value[*instanceSDK.Server](t, ctx.Result)
size0 := testhelpers.MapTValue(t, server.Volumes, "0").Size
size1 := testhelpers.MapTValue(t, server.Volumes, "1").Size
assert.Equal(t, 20*scw.GB, instance.SizeValue(size0), "Size of volume should be 20 GB")
assert.Equal(t, 20*scw.GB, instance.SizeValue(size1), "Size of volume should be 20 GB")
},
testServerSBSVolumeSize("0", 20),
testServerSBSVolumeSize("1", 20),
),
AfterFunc: core.AfterFuncCombine(
deleteServer("Server"),
deleteServerAfterFunc(),
deleteSnapshot("Snapshot"),
deleteBlockSnapshot("Snapshot"),
),
}))

Expand Down
5 changes: 5 additions & 0 deletions internal/namespaces/instance/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func deleteSnapshot(metaKey string) core.AfterFunc {
return core.ExecAfterCmd("scw instance snapshot delete {{ ." + metaKey + ".Snapshot.ID }}")
}

// deleteSnapshot deletes a snapshot previously registered in the context Meta at metaKey.
func deleteBlockSnapshot(metaKey string) core.AfterFunc {
return core.ExecAfterCmd("scw block snapshot delete {{ ." + metaKey + ".ID }}")
}

func createPN() core.BeforeFunc {
return core.ExecStoreBeforeCmd(
"PN",
Expand Down

0 comments on commit 839d2d0

Please sign in to comment.