Skip to content

Commit 4ac6d23

Browse files
committed
test(instance): add test
1 parent 69b41c7 commit 4ac6d23

5 files changed

+4906
-0
lines changed

internal/namespaces/instance/v1/custom_image_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55

66
"github.com/scaleway/scaleway-cli/v2/core"
7+
block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1"
78
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1"
89
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
910
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -111,6 +112,50 @@ func createImage(metaKey string) core.BeforeFunc {
111112
)
112113
}
113114

115+
func createImageWithSBSRootVolume(metaKey string) core.BeforeFunc {
116+
return core.BeforeFuncCombine(
117+
core.ExecStoreBeforeCmd(
118+
"Server",
119+
testServerCommand("stopped=true image=ubuntu-jammy root-volume=sbs:20G:5000 --wait"),
120+
),
121+
core.ExecStoreBeforeCmd(
122+
"Snapshot",
123+
`scw block snapshot create volume-id={{ (index .Server.Volumes "0").ID }} --wait`,
124+
),
125+
core.ExecStoreBeforeCmd(
126+
metaKey,
127+
`scw instance image create snapshot-id={{ .Snapshot.ID }} arch=x86_64`,
128+
),
129+
)
130+
}
131+
132+
func createImageWithSBSAdditionalVolumes(metaKey string) core.BeforeFunc {
133+
return core.BeforeFuncCombine(
134+
core.ExecStoreBeforeCmd(
135+
"Server",
136+
testServerCommand(
137+
"stopped=true image=ubuntu-jammy root-volume=local:20G additional-volumes.0=sbs:10GB:5000 additional-volumes.1=sbs:15GB:15000 --wait",
138+
),
139+
),
140+
core.ExecStoreBeforeCmd(
141+
"SnapshotRoot",
142+
`scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }} --wait`,
143+
),
144+
core.ExecStoreBeforeCmd(
145+
"SnapshotAdditional1",
146+
`scw block snapshot create volume-id={{ (index .Server.Volumes "1").ID }} --wait`,
147+
),
148+
core.ExecStoreBeforeCmd(
149+
"SnapshotAdditional2",
150+
`scw block snapshot create volume-id={{ (index .Server.Volumes "2").ID }} --wait`,
151+
),
152+
core.ExecStoreBeforeCmd(
153+
metaKey,
154+
`scw instance image create snapshot-id={{ .SnapshotRoot.ID }} additional-volumes.0.id={{ .SnapshotAdditional1.ID }} additional-volumes.1.id={{ .SnapshotAdditional2.ID }} arch=x86_64`,
155+
),
156+
)
157+
}
158+
114159
func deleteImage(metaKey string) core.AfterFunc {
115160
return core.ExecAfterCmd(
116161
`scw instance image delete {{ .` + metaKey + `.Image.ID }} with-snapshots=true`,
@@ -128,6 +173,34 @@ func Test_ImageList(t *testing.T) {
128173
),
129174
AfterFunc: deleteImage("Image"),
130175
}))
176+
177+
t.Run("With SBS root volume", core.Test(&core.TestConfig{
178+
BeforeFunc: createImageWithSBSRootVolume("ImageSBSRoot"),
179+
Commands: core.NewCommandsMerge(
180+
instance.GetCommands(),
181+
block.GetCommands(),
182+
),
183+
Cmd: "scw instance image list",
184+
Check: core.TestCheckCombine(
185+
core.TestCheckGolden(),
186+
core.TestCheckExitCode(0),
187+
),
188+
AfterFunc: deleteImage("ImageSBSRoot"),
189+
}))
190+
191+
t.Run("With SBS additional volumes", core.Test(&core.TestConfig{
192+
BeforeFunc: createImageWithSBSAdditionalVolumes("ImageSBSAdditional"),
193+
Commands: core.NewCommandsMerge(
194+
instance.GetCommands(),
195+
block.GetCommands(),
196+
),
197+
Cmd: "scw instance image list",
198+
Check: core.TestCheckCombine(
199+
core.TestCheckGolden(),
200+
core.TestCheckExitCode(0),
201+
),
202+
AfterFunc: deleteImage("ImageSBSAdditional"),
203+
}))
131204
}
132205

133206
func Test_ImageUpdate(t *testing.T) {

0 commit comments

Comments
 (0)