Skip to content

Commit 0e60089

Browse files
authored
test(instance): remove unused parameters from test helper functions (#5212)
1 parent bf71b6d commit 0e60089

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

internal/namespaces/instance/v1/custom_image_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func Test_ImageUpdate(t *testing.T) {
280280
AfterFunc: core.AfterFuncCombine(
281281
deleteServer("Server"),
282282
deleteImage("ImageExtraVol"),
283-
deleteVolume("Volume"),
283+
deleteVolume(),
284284
),
285285
})
286286
})

internal/namespaces/instance/v1/custom_server_create_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ func Test_CreateServer(t *testing.T) {
328328
block.GetCommands(),
329329
),
330330
BeforeFunc: core.BeforeFuncCombine(
331-
createSbsVolume("Volume", 20),
331+
createSbsVolume(20),
332332
),
333333
Cmd: testServerCommand(
334334
"image=ubuntu_jammy additional-volumes.0={{.Volume.ID}} stopped=true",
@@ -381,7 +381,7 @@ func Test_CreateServer(t *testing.T) {
381381
block.GetCommands(),
382382
),
383383
BeforeFunc: core.BeforeFuncCombine(
384-
createSbsVolume("Volume", 20),
384+
createSbsVolume(20),
385385
),
386386
Cmd: testServerCommand("image=none root-volume={{.Volume.ID}} stopped=true"),
387387
Check: core.TestCheckCombine(
@@ -689,13 +689,13 @@ func Test_CreateServerErrors(t *testing.T) {
689689

690690
t.Run("Error: invalid total local volumes size: too low 3", core.Test(&core.TestConfig{
691691
Commands: instance.GetCommands(),
692-
BeforeFunc: createVolume("Volume", 5, instanceSDK.VolumeVolumeTypeLSSD),
692+
BeforeFunc: createVolume(5),
693693
Cmd: testServerCommand("image=ubuntu_jammy root-volume={{ .Volume.ID }}"),
694694
Check: core.TestCheckCombine(
695695
core.TestCheckGolden(),
696696
core.TestCheckExitCode(1),
697697
),
698-
AfterFunc: deleteVolume("Volume"),
698+
AfterFunc: deleteVolume(),
699699
DisableParallel: true,
700700
}))
701701

@@ -723,15 +723,15 @@ func Test_CreateServerErrors(t *testing.T) {
723723

724724
t.Run("Error: invalid total local volumes size: too high 3", core.Test(&core.TestConfig{
725725
Commands: instance.GetCommands(),
726-
BeforeFunc: createVolume("Volume", 20, instanceSDK.VolumeVolumeTypeLSSD),
726+
BeforeFunc: createVolume(20),
727727
Cmd: testServerCommand(
728728
"image=ubuntu_jammy root-volume={{ .Volume.ID }} additional-volumes.0=local:10GB",
729729
),
730730
Check: core.TestCheckCombine(
731731
core.TestCheckGolden(),
732732
core.TestCheckExitCode(1),
733733
),
734-
AfterFunc: deleteVolume("Volume"),
734+
AfterFunc: deleteVolume(),
735735
DisableParallel: true,
736736
}))
737737

@@ -749,13 +749,13 @@ func Test_CreateServerErrors(t *testing.T) {
749749

750750
t.Run("Error: disallow existing root volume ID", core.Test(&core.TestConfig{
751751
Commands: instance.GetCommands(),
752-
BeforeFunc: createVolume("Volume", 20, instanceSDK.VolumeVolumeTypeLSSD),
752+
BeforeFunc: createVolume(20),
753753
Cmd: testServerCommand("image=ubuntu_jammy root-volume={{ .Volume.ID }}"),
754754
Check: core.TestCheckCombine(
755755
core.TestCheckGolden(),
756756
core.TestCheckExitCode(1),
757757
),
758-
AfterFunc: deleteVolume("Volume"),
758+
AfterFunc: deleteVolume(),
759759
DisableParallel: true,
760760
}))
761761

internal/namespaces/instance/v1/custom_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
2525
),
2626
BeforeFunc: core.BeforeFuncCombine(
2727
createServer("Server"),
28-
createSbsVolume("Volume", 10),
28+
createSbsVolume(10),
2929
),
3030
Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}",
3131
Check: core.TestCheckCombine(
@@ -51,7 +51,7 @@ func Test_ServerVolumeUpdate(t *testing.T) {
5151
Commands: instance.GetCommands(),
5252
BeforeFunc: core.BeforeFuncCombine(
5353
createServer("Server"),
54-
createVolume("Volume", 10, instanceSDK.VolumeVolumeTypeLSSD),
54+
createVolume(10),
5555
),
5656
Cmd: "scw instance server attach-volume server-id={{ .Server.ID }} volume-id={{ .Volume.ID }}",
5757
Check: core.TestCheckCombine(
@@ -283,7 +283,7 @@ func Test_ServerUpdateCustom(t *testing.T) {
283283
),
284284
BeforeFunc: core.BeforeFuncCombine(
285285
createServer("Server"),
286-
createSbsVolume("Volume", 10),
286+
createSbsVolume(10),
287287
),
288288
Cmd: `scw instance server update {{ .Server.ID }} volume-ids.0={{ (index .Server.Volumes "0").ID }} volume-ids.1={{ .Volume.ID }}`,
289289
Check: core.TestCheckCombine(

internal/namespaces/instance/v1/custom_snapshot_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_UpdateSnapshot(t *testing.T) {
3737
),
3838
AfterFunc: core.AfterFuncCombine(
3939
deleteSnapshot("CreateSnapshot"),
40-
deleteVolume("Volume"),
40+
deleteVolume(),
4141
),
4242
}))
4343
t.Run("Change name", core.Test(&core.TestConfig{
@@ -65,7 +65,7 @@ func Test_UpdateSnapshot(t *testing.T) {
6565
),
6666
AfterFunc: core.AfterFuncCombine(
6767
deleteSnapshot("CreateSnapshot"),
68-
deleteVolume("Volume"),
68+
deleteVolume(),
6969
),
7070
}))
7171
})

internal/namespaces/instance/v1/helpers_test.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,31 @@ func deleteServer(metaKey string) core.AfterFunc {
8787
//
8888

8989
// createVolume creates a volume of the given size and type and
90-
// register it in the context Meta at metaKey.
90+
// register it in the context Meta at "Volume".
9191
func createVolume(
92-
metaKey string,
9392
sizeInGb int,
94-
volumeType instanceSDK.VolumeVolumeType,
9593
) core.BeforeFunc {
9694
return func(ctx *core.BeforeFuncCtx) error {
9795
cmd := fmt.Sprintf(
98-
"scw instance volume create name=cli-test size=%dGB volume-type=%s",
96+
"scw instance volume create name=cli-test size=%dGB volume-type=l_ssd",
9997
sizeInGb,
100-
volumeType,
10198
)
10299
res := ctx.ExecuteCmd(strings.Split(cmd, " "))
103100
createVolumeResponse := res.(*instanceSDK.CreateVolumeResponse)
104-
ctx.Meta[metaKey] = createVolumeResponse.Volume
101+
ctx.Meta["Volume"] = createVolumeResponse.Volume
105102

106103
return nil
107104
}
108105
}
109106

110-
// deleteVolume deletes a volume previously registered in the context Meta at metaKey.
111-
func deleteVolume(metaKey string) core.AfterFunc {
112-
return core.ExecAfterCmd("scw instance volume delete {{ ." + metaKey + ".ID }}")
107+
// deleteVolume deletes a volume previously registered in the context Meta at "Volume".
108+
func deleteVolume() core.AfterFunc {
109+
return core.ExecAfterCmd("scw instance volume delete {{ .Volume.ID }}")
113110
}
114111

115112
// createSbsVolume creates a volume of the given size and
116-
// register it in the context Meta at metaKey
117-
func createSbsVolume(metaKey string, sizeInGb int) core.BeforeFunc {
113+
// register it in the context Meta at "Volume".
114+
func createSbsVolume(sizeInGb int) core.BeforeFunc {
118115
return func(ctx *core.BeforeFuncCtx) error {
119116
cmd := fmt.Sprintf(
120117
"scw block volume create name=%s from-empty.size=%dGB perf-iops=5000 -w",
@@ -123,7 +120,7 @@ func createSbsVolume(metaKey string, sizeInGb int) core.BeforeFunc {
123120
)
124121
res := ctx.ExecuteCmd(strings.Split(cmd, " "))
125122
volume := res.(*block.Volume)
126-
ctx.Meta[metaKey] = volume
123+
ctx.Meta["Volume"] = volume
127124

128125
return nil
129126
}

0 commit comments

Comments
 (0)