Skip to content

Commit 3bc2346

Browse files
authored
tests(lb): clean flex ips + add delete waiter (#4409)
1 parent 9105d29 commit 3bc2346

File tree

46 files changed

+13416
-10675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+13416
-10675
lines changed

cmd/scw/testdata/test-all-usage-lblb-delete-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ARGS:
1212

1313
FLAGS:
1414
-h, --help help for delete
15+
-w, --wait wait until the lb is ready
1516

1617
GLOBAL FLAGS:
1718
-c, --config string The path to the config file

internal/namespaces/lb/v1/custom_backend_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func Test_GetBackend(t *testing.T) {
2525
AfterFunc: core.AfterFuncCombine(
2626
deleteLB(),
2727
deleteInstance(),
28+
deleteLBFlexibleIP(),
2829
),
2930
}))
3031
}
@@ -44,6 +45,7 @@ func Test_CreateBackend(t *testing.T) {
4445
AfterFunc: core.AfterFuncCombine(
4546
deleteLB(),
4647
deleteRunningInstance(),
48+
deleteLBFlexibleIP(),
4749
),
4850
}))
4951

@@ -58,6 +60,7 @@ func Test_CreateBackend(t *testing.T) {
5860
AfterFunc: core.AfterFuncCombine(
5961
deleteLB(),
6062
deleteRunningInstance(),
63+
deleteLBFlexibleIP(),
6164
),
6265
}))
6366

@@ -72,6 +75,7 @@ func Test_CreateBackend(t *testing.T) {
7275
AfterFunc: core.AfterFuncCombine(
7376
deleteLB(),
7477
deleteRunningInstance(),
78+
deleteLBFlexibleIP(),
7579
),
7680
}))
7781

@@ -86,6 +90,7 @@ func Test_CreateBackend(t *testing.T) {
8690
AfterFunc: core.AfterFuncCombine(
8791
deleteLB(),
8892
deleteRunningInstance(),
93+
deleteLBFlexibleIP(),
8994
),
9095
}))
9196
}
@@ -106,6 +111,7 @@ func Test_AddBackendServers(t *testing.T) {
106111
AfterFunc: core.AfterFuncCombine(
107112
deleteLB(),
108113
deleteRunningInstance(),
114+
deleteLBFlexibleIP(),
109115
),
110116
}))
111117

@@ -121,6 +127,7 @@ func Test_AddBackendServers(t *testing.T) {
121127
AfterFunc: core.AfterFuncCombine(
122128
deleteLB(),
123129
deleteRunningInstance(),
130+
deleteLBFlexibleIP(),
124131
),
125132
}))
126133

@@ -136,6 +143,7 @@ func Test_AddBackendServers(t *testing.T) {
136143
AfterFunc: core.AfterFuncCombine(
137144
deleteLB(),
138145
deleteRunningInstance(),
146+
deleteLBFlexibleIP(),
139147
),
140148
}))
141149

@@ -151,6 +159,7 @@ func Test_AddBackendServers(t *testing.T) {
151159
AfterFunc: core.AfterFuncCombine(
152160
deleteLB(),
153161
deleteRunningInstance(),
162+
deleteLBFlexibleIP(),
154163
),
155164
}))
156165
}

internal/namespaces/lb/v1/custom_certificate_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ FKQ9WcK8j+KuYrWQJihn/omlWXSQ+zs12N7yKVLVRuY8aw4XuWZwvuu4EkRLYcUD
108108
"scw", "lb", "certificate", "create",
109109
"lb-id={{ .LB.ID }}", "custom-certificate-chain=" + customCertificateChain,
110110
},
111-
Check: core.TestCheckGolden(),
112-
AfterFunc: deleteLB(),
111+
Check: core.TestCheckGolden(),
112+
AfterFunc: core.AfterFuncCombine(
113+
deleteLB(),
114+
deleteLBFlexibleIP(),
115+
),
113116
TmpHomeDir: true,
114117
}))
115118
}

internal/namespaces/lb/v1/custom_frontend_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func Test_GetFrontend(t *testing.T) {
2525
AfterFunc: core.AfterFuncCombine(
2626
deleteLB(),
2727
deleteInstance(),
28+
deleteLBFlexibleIP(),
2829
),
2930
}))
3031
}

internal/namespaces/lb/v1/custom_lb.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package lb
22

33
import (
44
"context"
5+
"errors"
6+
"net/http"
57
"reflect"
68
"strings"
79
"time"
@@ -223,6 +225,26 @@ func lbUpdateBuilder(c *core.Command) *core.Command {
223225
}
224226

225227
func lbDeleteBuilder(c *core.Command) *core.Command {
228+
c.WaitFunc = func(ctx context.Context, argsI interface{}, _ interface{}) (interface{}, error) {
229+
api := lb.NewZonedAPI(core.ExtractClient(ctx))
230+
waitForLb, err := api.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
231+
LBID: argsI.(*lb.ZonedAPIDeleteLBRequest).LBID,
232+
Zone: argsI.(*lb.ZonedAPIDeleteLBRequest).Zone,
233+
RetryInterval: core.DefaultRetryInterval,
234+
})
235+
if err != nil {
236+
notFoundError := &scw.ResourceNotFoundError{}
237+
responseError := &scw.ResponseError{}
238+
if errors.As(err, &responseError) && responseError.StatusCode == http.StatusNotFound || errors.As(err, &notFoundError) {
239+
return &core.SuccessResult{
240+
Resource: "lb",
241+
Verb: "delete",
242+
}, nil
243+
}
244+
return nil, err
245+
}
246+
return waitForLb, nil
247+
}
226248
c.Interceptor = interceptLB()
227249
return c
228250
}

internal/namespaces/lb/v1/custom_lb_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ func Test_ListLB(t *testing.T) {
1616
BeforeFunc: createLB(),
1717
Cmd: "scw lb lb list",
1818
Check: core.TestCheckGolden(),
19-
AfterFunc: deleteLB(),
19+
AfterFunc: core.AfterFuncCombine(
20+
deleteLB(),
21+
deleteLBFlexibleIP(),
22+
),
2023
}))
2124
}
2225

2326
func Test_CreateLB(t *testing.T) {
2427
t.Run("Simple", core.Test(&core.TestConfig{
25-
Commands: lb.GetCommands(),
26-
Cmd: "scw lb lb create name=foobar description=foobar --wait",
27-
Check: core.TestCheckGolden(),
28-
AfterFunc: core.ExecAfterCmd("scw lb lb delete {{ .CmdResult.ID }}"),
28+
Commands: lb.GetCommands(),
29+
Cmd: "scw lb lb create name=foobar description=foobar --wait",
30+
Check: core.TestCheckGolden(),
31+
AfterFunc: core.AfterFuncCombine(
32+
core.ExecAfterCmd("scw lb lb delete {{ .CmdResult.ID }} --wait"),
33+
core.ExecAfterCmd("scw lb ip delete {{ (index .CmdResult.IP 0).ID }}"),
34+
),
2935
}))
3036
}
3137

@@ -35,7 +41,10 @@ func Test_GetLB(t *testing.T) {
3541
BeforeFunc: createLB(),
3642
Cmd: "scw lb lb get {{ .LB.ID }}",
3743
Check: core.TestCheckGolden(),
38-
AfterFunc: deleteLB(),
44+
AfterFunc: core.AfterFuncCombine(
45+
deleteLB(),
46+
deleteLBFlexibleIP(),
47+
),
3948
}))
4049
}
4150

@@ -48,7 +57,10 @@ func Test_UpdateLBIPv6(t *testing.T) {
4857
core.TestCheckExitCode(0),
4958
core.TestCheckGolden(),
5059
),
51-
AfterFunc: deleteLB(),
60+
AfterFunc: core.AfterFuncCombine(
61+
deleteLB(),
62+
deleteLBFlexibleIP(),
63+
),
5264
}))
5365

5466
t.Run("IPID", core.Test(&core.TestConfig{
@@ -73,9 +85,12 @@ func Test_WaitLB(t *testing.T) {
7385
"LB",
7486
"scw lb lb create name=cli-test description=cli-test",
7587
),
76-
Cmd: "scw lb lb wait {{ .LB.ID }}",
77-
Check: core.TestCheckGolden(),
78-
AfterFunc: deleteLB(),
88+
Cmd: "scw lb lb wait {{ .LB.ID }}",
89+
Check: core.TestCheckGolden(),
90+
AfterFunc: core.AfterFuncCombine(
91+
deleteLB(),
92+
deleteLBFlexibleIP(),
93+
),
7994
}))
8095
}
8196

@@ -104,6 +119,7 @@ func Test_GetStats(t *testing.T) {
104119
AfterFunc: core.AfterFuncCombine(
105120
deleteLB(),
106121
deleteInstance(),
122+
deleteLBFlexibleIP(),
107123
),
108124
}))
109125
}

internal/namespaces/lb/v1/custom_private_network_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ func Test_ListLBPrivateNetwork(t *testing.T) {
2727
deleteLB(),
2828
core.AfterFuncWhenUpdatingCassette(
2929
func(_ *core.AfterFuncCtx) error {
30-
time.Sleep(10 * time.Second)
30+
time.Sleep(1 * time.Minute)
3131
return nil
3232
},
3333
),
3434
deletePN(),
35+
deleteLBFlexibleIP(),
3536
),
3637
}))
3738
}

internal/namespaces/lb/v1/helper_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ func createLB() core.BeforeFunc {
2121
}
2222

2323
func deleteLB() core.AfterFunc {
24-
return core.ExecAfterCmd("scw lb lb delete {{ .LB.ID }}")
24+
return core.ExecAfterCmd("scw lb lb delete {{ .LB.ID }} --wait")
25+
}
26+
27+
func deleteLBFlexibleIP() core.AfterFunc {
28+
return core.ExecAfterCmd("scw lb ip delete {{ (index .LB.IP 0).ID }}")
2529
}
2630

2731
func createInstance() core.BeforeFunc {

0 commit comments

Comments
 (0)