Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-all-usage-lblb-delete-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ARGS:

FLAGS:
-h, --help help for delete
-w, --wait wait until the lb is ready

GLOBAL FLAGS:
-c, --config string The path to the config file
Expand Down
9 changes: 9 additions & 0 deletions internal/namespaces/lb/v1/custom_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Test_GetBackend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteInstance(),
deleteLBFlexibleIP(),
),
}))
}
Expand All @@ -44,6 +45,7 @@ func Test_CreateBackend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -58,6 +60,7 @@ func Test_CreateBackend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -72,6 +75,7 @@ func Test_CreateBackend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -86,6 +90,7 @@ func Test_CreateBackend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))
}
Expand All @@ -106,6 +111,7 @@ func Test_AddBackendServers(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -121,6 +127,7 @@ func Test_AddBackendServers(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -136,6 +143,7 @@ func Test_AddBackendServers(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))

Expand All @@ -151,6 +159,7 @@ func Test_AddBackendServers(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteRunningInstance(),
deleteLBFlexibleIP(),
),
}))
}
7 changes: 5 additions & 2 deletions internal/namespaces/lb/v1/custom_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ FKQ9WcK8j+KuYrWQJihn/omlWXSQ+zs12N7yKVLVRuY8aw4XuWZwvuu4EkRLYcUD
"scw", "lb", "certificate", "create",
"lb-id={{ .LB.ID }}", "custom-certificate-chain=" + customCertificateChain,
},
Check: core.TestCheckGolden(),
AfterFunc: deleteLB(),
Check: core.TestCheckGolden(),
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteLBFlexibleIP(),
),
TmpHomeDir: true,
}))
}
1 change: 1 addition & 0 deletions internal/namespaces/lb/v1/custom_frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Test_GetFrontend(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteInstance(),
deleteLBFlexibleIP(),
),
}))
}
22 changes: 22 additions & 0 deletions internal/namespaces/lb/v1/custom_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package lb

import (
"context"
"errors"
"net/http"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -223,6 +225,26 @@ func lbUpdateBuilder(c *core.Command) *core.Command {
}

func lbDeleteBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI interface{}, _ interface{}) (interface{}, error) {
api := lb.NewZonedAPI(core.ExtractClient(ctx))
waitForLb, err := api.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
LBID: argsI.(*lb.ZonedAPIDeleteLBRequest).LBID,
Zone: argsI.(*lb.ZonedAPIDeleteLBRequest).Zone,
RetryInterval: core.DefaultRetryInterval,
})
if err != nil {
notFoundError := &scw.ResourceNotFoundError{}
responseError := &scw.ResponseError{}
if errors.As(err, &responseError) && responseError.StatusCode == http.StatusNotFound || errors.As(err, &notFoundError) {
return &core.SuccessResult{
Resource: "lb",
Verb: "delete",
}, nil
}
return nil, err
}
return waitForLb, nil
}
c.Interceptor = interceptLB()
return c
}
Expand Down
36 changes: 26 additions & 10 deletions internal/namespaces/lb/v1/custom_lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ func Test_ListLB(t *testing.T) {
BeforeFunc: createLB(),
Cmd: "scw lb lb list",
Check: core.TestCheckGolden(),
AfterFunc: deleteLB(),
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteLBFlexibleIP(),
),
}))
}

func Test_CreateLB(t *testing.T) {
t.Run("Simple", core.Test(&core.TestConfig{
Commands: lb.GetCommands(),
Cmd: "scw lb lb create name=foobar description=foobar --wait",
Check: core.TestCheckGolden(),
AfterFunc: core.ExecAfterCmd("scw lb lb delete {{ .CmdResult.ID }}"),
Commands: lb.GetCommands(),
Cmd: "scw lb lb create name=foobar description=foobar --wait",
Check: core.TestCheckGolden(),
AfterFunc: core.AfterFuncCombine(
core.ExecAfterCmd("scw lb lb delete {{ .CmdResult.ID }} --wait"),
core.ExecAfterCmd("scw lb ip delete {{ (index .CmdResult.IP 0).ID }}"),
),
}))
}

Expand All @@ -35,7 +41,10 @@ func Test_GetLB(t *testing.T) {
BeforeFunc: createLB(),
Cmd: "scw lb lb get {{ .LB.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: deleteLB(),
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteLBFlexibleIP(),
),
}))
}

Expand All @@ -48,7 +57,10 @@ func Test_UpdateLBIPv6(t *testing.T) {
core.TestCheckExitCode(0),
core.TestCheckGolden(),
),
AfterFunc: deleteLB(),
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteLBFlexibleIP(),
),
}))

t.Run("IPID", core.Test(&core.TestConfig{
Expand All @@ -73,9 +85,12 @@ func Test_WaitLB(t *testing.T) {
"LB",
"scw lb lb create name=cli-test description=cli-test",
),
Cmd: "scw lb lb wait {{ .LB.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: deleteLB(),
Cmd: "scw lb lb wait {{ .LB.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteLBFlexibleIP(),
),
}))
}

Expand Down Expand Up @@ -104,6 +119,7 @@ func Test_GetStats(t *testing.T) {
AfterFunc: core.AfterFuncCombine(
deleteLB(),
deleteInstance(),
deleteLBFlexibleIP(),
),
}))
}
Expand Down
3 changes: 2 additions & 1 deletion internal/namespaces/lb/v1/custom_private_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func Test_ListLBPrivateNetwork(t *testing.T) {
deleteLB(),
core.AfterFuncWhenUpdatingCassette(
func(_ *core.AfterFuncCtx) error {
time.Sleep(10 * time.Second)
time.Sleep(1 * time.Minute)
return nil
},
),
deletePN(),
deleteLBFlexibleIP(),
),
}))
}
6 changes: 5 additions & 1 deletion internal/namespaces/lb/v1/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func createLB() core.BeforeFunc {
}

func deleteLB() core.AfterFunc {
return core.ExecAfterCmd("scw lb lb delete {{ .LB.ID }}")
return core.ExecAfterCmd("scw lb lb delete {{ .LB.ID }} --wait")
}

func deleteLBFlexibleIP() core.AfterFunc {
return core.ExecAfterCmd("scw lb ip delete {{ (index .LB.IP 0).ID }}")
}

func createInstance() core.BeforeFunc {
Expand Down
Loading
Loading