@@ -6,10 +6,10 @@ import (
6
6
"github.com/alecthomas/assert"
7
7
"github.com/scaleway/scaleway-cli/v2/core"
8
8
"github.com/scaleway/scaleway-cli/v2/internal/interactive"
9
- blockCli "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1"
9
+ block "github.com/scaleway/scaleway-cli/v2/internal/namespaces/block/v1alpha1"
10
10
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/instance/v1"
11
11
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
12
- block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
12
+ blockSDK "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
13
13
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
14
14
"github.com/scaleway/scaleway-sdk-go/scw"
15
15
"github.com/stretchr/testify/require"
@@ -73,7 +73,10 @@ func Test_ServerVolumeUpdate(t *testing.T) {
73
73
})
74
74
t .Run ("Detach" , func (t * testing.T ) {
75
75
t .Run ("simple block volume" , core .Test (& core.TestConfig {
76
- Commands : instance .GetCommands (),
76
+ Commands : core .NewCommandsMerge (
77
+ block .GetCommands (),
78
+ instance .GetCommands (),
79
+ ),
77
80
BeforeFunc : core .ExecStoreBeforeCmd ("Server" , testServerCommand ("stopped=true image=ubuntu-bionic additional-volumes.0=block:10G" )),
78
81
Cmd : `scw instance server detach-volume volume-id={{ (index .Server.Volumes "1").ID }}` ,
79
82
Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
@@ -85,7 +88,8 @@ func Test_ServerVolumeUpdate(t *testing.T) {
85
88
assert .Equal (t , 1 , len (ctx .Result .(* instanceSDK.DetachVolumeResponse ).Server .Volumes ))
86
89
},
87
90
AfterFunc : core .AfterFuncCombine (
88
- core .ExecAfterCmd (`scw instance volume delete {{ (index .Server.Volumes "1").ID }}` ),
91
+ core .ExecAfterCmd (`scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}` ),
92
+ core .ExecAfterCmd (`scw block volume delete {{ (index .Server.Volumes "1").ID }}` ),
89
93
deleteServer ("Server" ),
90
94
),
91
95
DisableParallel : true ,
@@ -246,7 +250,10 @@ func Test_ServerUpdateCustom(t *testing.T) {
246
250
}))
247
251
248
252
t .Run ("detach all volumes" , core .Test (& core.TestConfig {
249
- Commands : instance .GetCommands (),
253
+ Commands : core .NewCommandsMerge (
254
+ block .GetCommands (),
255
+ instance .GetCommands (),
256
+ ),
250
257
BeforeFunc : core .ExecStoreBeforeCmd ("Server" , testServerCommand ("stopped=true image=ubuntu-bionic additional-volumes.0=block:10G" )),
251
258
Cmd : `scw instance server update {{ .Server.ID }} volume-ids=none` ,
252
259
Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
@@ -255,8 +262,9 @@ func Test_ServerUpdateCustom(t *testing.T) {
255
262
assert .Equal (t , 0 , len (ctx .Result .(* instanceSDK.UpdateServerResponse ).Server .Volumes ))
256
263
},
257
264
AfterFunc : core .AfterFuncCombine (
258
- core .ExecAfterCmd (`scw instance volume delete {{ (index .Server.Volumes "0").ID }}` ),
259
- core .ExecAfterCmd (`scw instance volume delete {{ (index .Server.Volumes "1").ID }}` ),
265
+ core .ExecAfterCmd (`scw instance volume delete {{ (index .Server.Volumes "0").ID }}` ), // Local volume
266
+ core .ExecAfterCmd (`scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}` ),
267
+ core .ExecAfterCmd (`scw block volume delete {{ (index .Server.Volumes "1").ID }}` ),
260
268
deleteServer ("Server" ),
261
269
),
262
270
}))
@@ -292,14 +300,20 @@ func Test_ServerDelete(t *testing.T) {
292
300
}))
293
301
294
302
t .Run ("only local volumes" , core .Test (& core.TestConfig {
295
- Commands : instance .GetCommands (),
303
+ Commands : core .NewCommandsMerge (
304
+ block .GetCommands (),
305
+ instance .GetCommands (),
306
+ ),
296
307
BeforeFunc : core .ExecStoreBeforeCmd ("Server" , testServerCommand ("stopped=true image=ubuntu-bionic additional-volumes.0=block:10G" )),
297
308
Cmd : `scw instance server delete {{ .Server.ID }} with-ip=true with-volumes=local` ,
298
309
Check : core .TestCheckCombine (
299
310
core .TestCheckGolden (),
300
311
core .TestCheckExitCode (0 ),
301
312
),
302
- AfterFunc : core .ExecAfterCmd (`scw instance volume delete {{ (index .Server.Volumes "1").ID }}` ),
313
+ AfterFunc : core .AfterFuncCombine (
314
+ core .ExecAfterCmd (`scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}` ),
315
+ core .ExecAfterCmd (`scw block volume delete {{ (index .Server.Volumes "1").ID }}` ),
316
+ ),
303
317
DisableParallel : true ,
304
318
}))
305
319
@@ -327,7 +341,7 @@ func Test_ServerDelete(t *testing.T) {
327
341
t .Run ("with sbs volumes" , core .Test (& core.TestConfig {
328
342
Commands : core .NewCommandsMerge (
329
343
instance .GetCommands (),
330
- blockCli .GetCommands (),
344
+ block .GetCommands (),
331
345
),
332
346
BeforeFunc : core .BeforeFuncCombine (
333
347
core .ExecStoreBeforeCmd ("BlockVolume" , "scw block volume create perf-iops=5000 from-empty.size=10G name=cli-test-server-delete-with-sbs-volumes" ),
@@ -340,9 +354,9 @@ func Test_ServerDelete(t *testing.T) {
340
354
core .TestCheckExitCode (0 ),
341
355
func (t * testing.T , ctx * core.CheckFuncCtx ) {
342
356
t .Helper ()
343
- api := block .NewAPI (ctx .Client )
344
- blockVolume := ctx .Meta ["BlockVolume" ].(* block .Volume )
345
- resp , err := api .GetVolume (& block .GetVolumeRequest {
357
+ api := blockSDK .NewAPI (ctx .Client )
358
+ blockVolume := ctx .Meta ["BlockVolume" ].(* blockSDK .Volume )
359
+ resp , err := api .GetVolume (& blockSDK .GetVolumeRequest {
346
360
Zone : blockVolume .Zone ,
347
361
VolumeID : blockVolume .ID ,
348
362
})
0 commit comments