66 "github.com/scaleway/scaleway-cli/internal/core"
77 "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
88 "github.com/stretchr/testify/assert"
9+ "github.com/stretchr/testify/require"
910)
1011
1112func init () {
@@ -79,13 +80,13 @@ func Test_CreateVolume(t *testing.T) {
7980 t .Run ("Simple" , core .Test (& core.TestConfig {
8081 Commands : GetCommands (),
8182 Cmd : "scw instance volume create name=test size=20G" ,
82- AfterFunc : func (ctx * core.AfterFuncCtx ) error {
83- ctx .ExecuteCmd ("scw instance volume delete volume-id={{ .Volume.ID }}" )
84- return nil
85- },
8683 Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
8784 assert .Equal (t , "test" , ctx .Result .(* instance.CreateVolumeResponse ).Volume .Name )
8885 },
86+ AfterFunc : func (ctx * core.AfterFuncCtx ) error {
87+ ctx .ExecuteCmd ("scw instance volume delete volume-id=" + ctx .CmdResult .(* instance.CreateVolumeResponse ).Volume .ID )
88+ return nil
89+ },
8990 }))
9091
9192 t .Run ("Bad size unit" , core .Test (& core.TestConfig {
@@ -107,11 +108,12 @@ func Test_ServerUpdate(t *testing.T) {
107108 t .Run ("Simple" , core .Test (& core.TestConfig {
108109 Commands : GetCommands (),
109110 BeforeFunc : func (ctx * core.BeforeFuncCtx ) error {
110- ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic" )
111+ ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic stopped " )
111112 return nil
112113 },
113114 Cmd : "scw instance server update server-id={{ .Server.ID }}" ,
114115 Check : core .TestCheckCombine (
116+ core .TestCheckExitCode (0 ),
115117 core .TestCheckGolden (),
116118 ),
117119 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
@@ -127,9 +129,10 @@ func Test_ServerUpdate(t *testing.T) {
127129 return nil
128130 },
129131 Cmd : "scw instance server update server-id={{ .Server.ID }} placement-group=none" ,
130- Check : core .TestCheckCombine (
131- core .TestCheckNil (".Server.PlacementGroup" ),
132- ),
132+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
133+ require .NoError (t , ctx .Err )
134+ assert .Nil (t , ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup )
135+ },
133136 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
134137 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }}" )
135138 return nil
@@ -143,9 +146,10 @@ func Test_ServerUpdate(t *testing.T) {
143146 return nil
144147 },
145148 Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group=` ,
146- Check : core .TestCheckCombine (
147- core .TestCheckNil (".Server.PlacementGroup" ),
148- ),
149+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
150+ require .NoError (t , ctx .Err )
151+ assert .Nil (t , ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup )
152+ },
149153 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
150154 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true" )
151155 return nil
@@ -159,10 +163,14 @@ func Test_ServerUpdate(t *testing.T) {
159163 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic stopped" )
160164 return nil
161165 },
162- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group={{ .PlacementGroup.PlacementGroup.ID }}` ,
163- Check : core .TestCheckCombine (
164- core .TestCheckEqual (".PlacementGroup.PlacementGroup.ID" , ".Server.PlacementGroup.ID" ),
165- ),
166+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}` ,
167+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
168+ require .NoError (t , ctx .Err )
169+ assert .Equal (t ,
170+ ctx .Meta ["PlacementGroup" ].(* instance.CreatePlacementGroupResponse ).PlacementGroup .ID ,
171+ ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup .ID ,
172+ )
173+ },
166174 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
167175 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true" )
168176 ctx .ExecuteCmd ("scw instance placement-group delete placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}" )
@@ -176,8 +184,9 @@ func Test_ServerUpdate(t *testing.T) {
176184 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic stopped" )
177185 return nil
178186 },
179- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group=11111111-1111-1111-1111-111111111111` ,
187+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id =11111111-1111-1111-1111-111111111111` ,
180188 Check : core .TestCheckCombine (
189+ core .TestCheckExitCode (1 ),
181190 core .TestCheckGolden (),
182191 ),
183192 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
@@ -192,8 +201,9 @@ func Test_ServerUpdate(t *testing.T) {
192201 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic stopped" )
193202 return nil
194203 },
195- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group=1111111` ,
204+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id =1111111` ,
196205 Check : core .TestCheckCombine (
206+ core .TestCheckExitCode (1 ),
197207 core .TestCheckGolden (),
198208 ),
199209 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
@@ -209,10 +219,11 @@ func Test_ServerUpdate(t *testing.T) {
209219 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic placement-group-id={{ .PlacementGroup.PlacementGroup.ID }} stopped" )
210220 return nil
211221 },
212- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group=none` ,
213- Check : core .TestCheckCombine (
214- core .TestCheckNil (".Server.PlacementGroup" ),
215- ),
222+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id=none` ,
223+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
224+ require .NoError (t , ctx .Err )
225+ assert .Nil (t , ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup )
226+ },
216227 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
217228 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true" )
218229 ctx .ExecuteCmd ("scw instance placement-group delete placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}" )
@@ -227,10 +238,14 @@ func Test_ServerUpdate(t *testing.T) {
227238 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic placement-group-id={{ .PlacementGroup.PlacementGroup.ID }} stopped" )
228239 return nil
229240 },
230- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group={{ .PlacementGroup.PlacementGroup.ID }}` ,
231- Check : core .TestCheckCombine (
232- core .TestCheckEqual (".PlacementGroup.PlacementGroup.ID" , ".Server.PlacementGroup.ID" ),
233- ),
241+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}` ,
242+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
243+ require .NoError (t , ctx .Err )
244+ assert .Equal (t ,
245+ ctx .Meta ["PlacementGroup" ].(* instance.CreatePlacementGroupResponse ).PlacementGroup .ID ,
246+ ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup .ID ,
247+ )
248+ },
234249 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
235250 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true" )
236251 ctx .ExecuteCmd ("scw instance placement-group delete placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}" )
@@ -246,13 +261,18 @@ func Test_ServerUpdate(t *testing.T) {
246261 ctx .Meta ["Server" ] = ctx .ExecuteCmd ("scw instance server create image=ubuntu-bionic placement-group-id={{ .PlacementGroup.PlacementGroup.ID }} stopped" )
247262 return nil
248263 },
249- Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group={{ .PlacementGroup2.PlacementGroup.ID }}` ,
250- Check : core .TestCheckCombine (
251- core .TestCheckEqual (".PlacementGroup2.PlacementGroup.ID" , ".Server.PlacementGroup.ID" ),
252- ),
264+ Cmd : `scw instance server update server-id={{ .Server.ID }} placement-group-id={{ .PlacementGroup2.PlacementGroup.ID }}` ,
265+ Check : func (t * testing.T , ctx * core.CheckFuncCtx ) {
266+ assert .NoError (t , ctx .Err )
267+ assert .Equal (t ,
268+ ctx .Meta ["PlacementGroup2" ].(* instance.CreatePlacementGroupResponse ).PlacementGroup .ID ,
269+ ctx .Result .(* instance.UpdateServerResponse ).Server .PlacementGroup .ID ,
270+ )
271+ },
253272 AfterFunc : func (ctx * core.AfterFuncCtx ) error {
254273 ctx .ExecuteCmd ("scw instance server delete server-id={{ .Server.ID }} delete-ip=true delete-volumes=true" )
255274 ctx .ExecuteCmd ("scw instance placement-group delete placement-group-id={{ .PlacementGroup.PlacementGroup.ID }}" )
275+ ctx .ExecuteCmd ("scw instance placement-group delete placement-group-id={{ .PlacementGroup2.PlacementGroup.ID }}" )
256276 return nil
257277 },
258278 }))
0 commit comments