Skip to content

Commit c174727

Browse files
committed
gather all server update tests in Test_ServerUpdate
1 parent 9f0d8d4 commit c174727

File tree

2 files changed

+303
-294
lines changed

2 files changed

+303
-294
lines changed

internal/namespaces/instance/v1/custom_server_test.go

Lines changed: 36 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -127,195 +127,45 @@ func Test_ServerVolumeUpdate(t *testing.T) {
127127
})
128128
}
129129

130-
func Test_ServerUpdateCustom(t *testing.T) {
131-
// IP cases.
132-
t.Run("Try to remove ip from server without ip", core.Test(&core.TestConfig{
133-
Commands: instance.GetCommands(),
134-
BeforeFunc: createServer("Server"),
135-
Cmd: "scw instance server update {{ .Server.ID }} ip=none",
136-
Check: core.TestCheckCombine(
137-
func(t *testing.T, ctx *core.CheckFuncCtx) {
138-
t.Helper()
139-
resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result)
140-
assert.Equal(t, (*instanceSDK.ServerIP)(nil), resp.Server.PublicIP)
141-
},
142-
core.TestCheckExitCode(0),
143-
),
144-
AfterFunc: deleteServer("Server"),
145-
}))
146-
147-
t.Run("Update server ip from server without ip", core.Test(&core.TestConfig{
148-
Commands: instance.GetCommands(),
149-
BeforeFunc: core.BeforeFuncCombine(
150-
createServer("Server"),
151-
createIP("IP"),
152-
),
153-
Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP.Address }}",
154-
Check: core.TestCheckCombine(
155-
func(t *testing.T, ctx *core.CheckFuncCtx) {
156-
t.Helper()
157-
ip := testhelpers.MapValue[*instanceSDK.IP](t, ctx.Meta, "IP")
158-
resp := testhelpers.Value[*instance.ServerWithWarningsResponse](t, ctx.Result)
159-
160-
assert.NotNil(t, resp.Server)
161-
assert.NotNil(t, resp.Server.PublicIP)
162-
assert.Equal(t, ip.Address, resp.Server.PublicIP.Address)
163-
},
164-
core.TestCheckExitCode(0),
165-
),
166-
AfterFunc: deleteServer("Server"),
167-
}))
168-
169-
t.Run("Update server ip from server with ip", core.Test(&core.TestConfig{
170-
Commands: instance.GetCommands(),
171-
BeforeFunc: core.BeforeFuncCombine(
172-
createServer("Server"),
173-
createIP("IP1"),
174-
createIP("IP2"),
175-
176-
// Attach IP1 to Server.
177-
core.ExecStoreBeforeCmd(
178-
"UpdatedServer",
179-
"scw instance server update {{ .Server.ID }} ip={{ .IP1.Address }}",
180-
),
181-
),
182-
Cmd: "scw instance server update {{ .Server.ID }} ip={{ .IP2.Address }}",
183-
Check: core.TestCheckCombine(
184-
func(t *testing.T, ctx *core.CheckFuncCtx) {
185-
t.Helper()
186-
// Test that the Server WAS attached to IP1.
187-
assert.Equal(
188-
t,
189-
ctx.Meta["IP1"].(*instanceSDK.IP).Address,
190-
ctx.Meta["UpdatedServer"].(*instance.ServerWithWarningsResponse).Server.PublicIP.Address,
191-
)
192-
// Test that the Server IS attached to IP2.
193-
assert.Equal(t,
194-
ctx.Meta["IP2"].(*instanceSDK.IP).Address,
195-
ctx.Result.(*instance.ServerWithWarningsResponse).Server.PublicIP.Address)
196-
},
197-
core.TestCheckExitCode(0),
198-
),
199-
AfterFunc: core.AfterFuncCombine(
200-
deleteServer("Server"),
201-
deleteIP("IP1"),
202-
),
203-
}))
204-
205-
// Placement group cases.
206-
t.Run(
207-
"Update server placement-group-id from server with placement-group-id",
208-
core.Test(&core.TestConfig{
209-
Commands: instance.GetCommands(),
210-
BeforeFunc: core.BeforeFuncCombine(
211-
createPlacementGroup("PlacementGroup1"),
212-
createPlacementGroup("PlacementGroup2"),
213-
core.ExecStoreBeforeCmd(
214-
"Server",
215-
testServerCommand(
216-
"stopped=true image=ubuntu-jammy placement-group-id={{ .PlacementGroup1.ID }}",
217-
),
218-
),
219-
),
220-
Cmd: "scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}",
221-
Check: core.TestCheckCombine(
222-
core.TestCheckExitCode(0),
223-
func(t *testing.T, ctx *core.CheckFuncCtx) {
224-
t.Helper()
225-
assert.Equal(t,
226-
ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID,
227-
ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID)
228-
},
229-
),
230-
AfterFunc: core.AfterFuncCombine(
231-
deleteServer("Server"),
232-
deletePlacementGroup("PlacementGroup1"),
233-
deletePlacementGroup("PlacementGroup2"),
234-
),
235-
}),
236-
)
130+
//func Test_ServerUpdateCustom(t *testing.T) {
131+
// Placement group cases.
132+
//t.Run(
133+
// "Update server placement-group-id from server with placement-group-id",
134+
// core.Test(&core.TestConfig{
135+
// Commands: instance.GetCommands(),
136+
// BeforeFunc: core.BeforeFuncCombine(
137+
// createPlacementGroup("PlacementGroup1"),
138+
// createPlacementGroup("PlacementGroup2"),
139+
// core.ExecStoreBeforeCmd(
140+
// "Server",
141+
// testServerCommand(
142+
// "stopped=true image=ubuntu-jammy placement-group-id={{ .PlacementGroup1.ID }}",
143+
// ),
144+
// ),
145+
// ),
146+
// Cmd: "scw instance server update {{ .Server.ID }} placement-group-id={{ .PlacementGroup2.ID }}",
147+
// Check: core.TestCheckCombine(
148+
// core.TestCheckExitCode(0),
149+
// func(t *testing.T, ctx *core.CheckFuncCtx) {
150+
// t.Helper()
151+
// assert.Equal(t,
152+
// ctx.Meta["PlacementGroup2"].(*instanceSDK.PlacementGroup).ID,
153+
// ctx.Result.(*instance.ServerWithWarningsResponse).Server.PlacementGroup.ID)
154+
// },
155+
// ),
156+
// AfterFunc: core.AfterFuncCombine(
157+
// deleteServer("Server"),
158+
// deletePlacementGroup("PlacementGroup1"),
159+
// deletePlacementGroup("PlacementGroup2"),
160+
// ),
161+
// }),
162+
//)
237163

238-
// Security group cases.
239-
t.Run(
240-
"Update server security-group-id from server with security-group-id",
241-
core.Test(&core.TestConfig{
242-
Commands: instance.GetCommands(),
243-
BeforeFunc: core.BeforeFuncCombine(
244-
createSecurityGroup("SecurityGroup1"),
245-
createSecurityGroup("SecurityGroup2"),
246-
core.ExecStoreBeforeCmd(
247-
"Server",
248-
testServerCommand(
249-
"stopped=true image=ubuntu-jammy security-group-id={{ .SecurityGroup1.ID }}",
250-
),
251-
),
252-
),
253-
Cmd: "scw instance server update {{ .Server.ID }} security-group-id={{ .SecurityGroup2.ID }}",
254-
Check: core.TestCheckCombine(
255-
core.TestCheckExitCode(0),
256-
func(t *testing.T, ctx *core.CheckFuncCtx) {
257-
t.Helper()
258-
assert.Equal(t,
259-
ctx.Meta["SecurityGroup2"].(*instanceSDK.SecurityGroup).ID,
260-
ctx.Result.(*instance.ServerWithWarningsResponse).Server.SecurityGroup.ID)
261-
},
262-
),
263-
AfterFunc: core.AfterFuncCombine(
264-
deleteServer("Server"),
265-
deleteSecurityGroup("SecurityGroup1"),
266-
deleteSecurityGroup("SecurityGroup2"),
267-
),
268-
}),
269-
)
164+
// Security group cases.
270165

271-
// Volumes cases.
272-
t.Run("Volumes", func(t *testing.T) {
273-
t.Run("valid simple block volume", core.Test(&core.TestConfig{
274-
Commands: core.NewCommandsMerge(
275-
block.GetCommands(),
276-
instance.GetCommands(),
277-
),
278-
BeforeFunc: core.BeforeFuncCombine(
279-
createServer("Server"),
280-
createSbsVolume("Volume", 10),
281-
),
282-
Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`,
283-
Check: core.TestCheckCombine(
284-
testServerUpdateServerSBSVolumeSize("0", 10),
285-
testServerUpdateServerSBSVolumeSize("1", 10),
286-
),
287-
AfterFunc: deleteServer("Server"),
288-
}))
166+
// Volumes cases.
289167

290-
t.Run("detach all volumes", core.Test(&core.TestConfig{
291-
Commands: core.NewCommandsMerge(
292-
block.GetCommands(),
293-
instance.GetCommands(),
294-
),
295-
BeforeFunc: core.ExecStoreBeforeCmd(
296-
"Server",
297-
testServerCommand("stopped=true image=ubuntu-jammy additional-volumes.0=block:10G"),
298-
),
299-
Cmd: `scw instance server update {{ .Server.ID }} volume-ids=none`,
300-
Check: func(t *testing.T, ctx *core.CheckFuncCtx) {
301-
t.Helper()
302-
require.NoError(t, ctx.Err)
303-
assert.Empty(t, ctx.Result.(*instance.ServerWithWarningsResponse).Server.Volumes)
304-
},
305-
AfterFunc: core.AfterFuncCombine(
306-
core.ExecAfterCmd(
307-
`scw block volume wait terminal-status=available {{ (index .Server.Volumes "0").ID }}`,
308-
),
309-
core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "0").ID }}`),
310-
core.ExecAfterCmd(
311-
`scw block volume wait terminal-status=available {{ (index .Server.Volumes "1").ID }}`,
312-
),
313-
core.ExecAfterCmd(`scw block volume delete {{ (index .Server.Volumes "1").ID }}`),
314-
deleteServer("Server"),
315-
),
316-
}))
317-
})
318-
}
168+
//}
319169

320170
// These tests needs to be run in sequence
321171
// since they are using the interactive print

0 commit comments

Comments
 (0)