Skip to content

Commit 283ebcf

Browse files
authored
fix(vpcgw):better vizualisation gw network dhcp (#3674)
1 parent f887258 commit 283ebcf

11 files changed

+1134
-226
lines changed

internal/namespaces/vpcgw/v1/custom.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ func GetCommands() *core.Commands {
1111

1212
human.RegisterMarshalerFunc(vpcgw.GatewayNetworkStatus(""), human.EnumMarshalFunc(gatewayNetworkStatusMarshalSpecs))
1313
human.RegisterMarshalerFunc(vpcgw.GatewayStatus(""), human.EnumMarshalFunc(gatewayStatusMarshalSpecs))
14-
human.RegisterMarshalerFunc(vpcgw.Gateway{}, gatewayNetworkMarshallerFunc)
14+
human.RegisterMarshalerFunc(vpcgw.Gateway{}, gatewayMarshalerFunc)
15+
human.RegisterMarshalerFunc(vpcgw.GatewayNetwork{}, gatewayNetworkMarshalerFunc)
1516

1617
cmds.MustFind("vpc-gw", "gateway-type", "list").Override(vpcgwGatewayTypeListBuilder)
1718
cmds.MustFind("vpc-gw", "gateway", "create").Override(gatewayCreateBuilder)

internal/namespaces/vpcgw/v1/custom_gateway.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ func gatewayCreateBuilder(c *core.Command) *core.Command {
4242
}
4343
return c
4444
}
45+
46+
func gatewayMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
47+
type tmp vpcgw.Gateway
48+
vpcgtw := tmp(i.(vpcgw.Gateway))
49+
opt.Sections = []*human.MarshalSection{
50+
{
51+
FieldName: "IP",
52+
Title: "IP",
53+
},
54+
{
55+
FieldName: "GatewayNetworks",
56+
Title: "GatewayNetworks",
57+
},
58+
}
59+
str, err := human.Marshal(vpcgtw, opt)
60+
if err != nil {
61+
return "", err
62+
}
63+
return str, nil
64+
}

internal/namespaces/vpcgw/v1/custom_gateway_network.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,16 @@ func gatewayNetworkDeleteBuilder(c *core.Command) *core.Command {
6464
return c
6565
}
6666

67-
func gatewayNetworkMarshallerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
68-
type tmp vpcgw.Gateway
69-
vpcgtwNetwork := tmp(i.(vpcgw.Gateway))
67+
func gatewayNetworkMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
68+
type tmp vpcgw.GatewayNetwork
69+
vpcgwNetwork := tmp(i.(vpcgw.GatewayNetwork))
7070
opt.Sections = []*human.MarshalSection{
7171
{
72-
FieldName: "IP",
73-
Title: "IP",
74-
},
75-
{
76-
FieldName: "GatewayNetworks",
77-
Title: "GatewayNetworks",
72+
FieldName: "DHCP",
73+
Title: "DHCP",
7874
},
7975
}
80-
str, err := human.Marshal(vpcgtwNetwork, opt)
76+
str, err := human.Marshal(vpcgwNetwork, opt)
8177
if err != nil {
8278
return "", err
8379
}

internal/namespaces/vpcgw/v1/custom_gateway_network_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
99
)
1010

11-
func Test_vpcGwGatewayGet(t *testing.T) {
11+
func Test_vpcGwGatewayNetworkGet(t *testing.T) {
1212
cmds := GetCommands()
1313
cmds.Merge(vpc.GetCommands())
1414

@@ -17,13 +17,15 @@ func Test_vpcGwGatewayGet(t *testing.T) {
1717
BeforeFunc: core.BeforeFuncCombine(
1818
testhelpers.CreatePN(),
1919
testhelpers.CreateGateway("GW"),
20-
testhelpers.CreateGatewayNetwork("GW"),
20+
testhelpers.CreateDHCP(),
21+
testhelpers.CreateGatewayNetworkDHCP("GW"),
2122
),
22-
Cmd: "scw vpc-gw gateway get {{ .GW.ID }}",
23+
Cmd: "scw vpc-gw gateway-network get {{ .GWNT.ID }}",
2324
Check: core.TestCheckGolden(),
2425
AfterFunc: core.AfterFuncCombine(
2526
testhelpers.DeleteGatewayNetwork(),
2627
testhelpers.DeletePN(),
28+
testhelpers.DeleteDHCP(),
2729
testhelpers.DeleteGateway("GW"),
2830
testhelpers.DeleteIPVpcGw("GW"),
2931
),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package vpcgw
2+
3+
import (
4+
"testing"
5+
6+
"github.com/scaleway/scaleway-cli/v2/internal/core"
7+
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpc/v2"
8+
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
9+
)
10+
11+
func Test_vpcGwGatewayGet(t *testing.T) {
12+
cmds := GetCommands()
13+
cmds.Merge(vpc.GetCommands())
14+
15+
t.Run("Simple", core.Test(&core.TestConfig{
16+
Commands: cmds,
17+
BeforeFunc: core.BeforeFuncCombine(
18+
testhelpers.CreatePN(),
19+
testhelpers.CreateGateway("GW"),
20+
testhelpers.CreateGatewayNetwork("GW"),
21+
),
22+
Cmd: "scw vpc-gw gateway get {{ .GW.ID }}",
23+
Check: core.TestCheckGolden(),
24+
AfterFunc: core.AfterFuncCombine(
25+
testhelpers.DeleteGatewayNetwork(),
26+
testhelpers.DeletePN(),
27+
testhelpers.DeleteGateway("GW"),
28+
testhelpers.DeleteIPVpcGw("GW"),
29+
),
30+
}))
31+
}

internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interactions:
77
form: {}
88
headers:
99
User-Agent:
10-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test
10+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.7; darwin; amd64) cli-e2e-test
1111
url: https://api.scaleway.com/vpc-gw/v1/zones/fr-par-1/gateway-types
1212
method: GET
1313
response:
@@ -21,17 +21,17 @@ interactions:
2121
Content-Type:
2222
- application/json
2323
Date:
24-
- Fri, 09 Feb 2024 10:04:35 GMT
24+
- Fri, 23 Feb 2024 14:58:24 GMT
2525
Server:
26-
- Scaleway API-Gateway
26+
- Scaleway API Gateway (fr-par-2;edge02)
2727
Strict-Transport-Security:
2828
- max-age=63072000
2929
X-Content-Type-Options:
3030
- nosniff
3131
X-Frame-Options:
3232
- DENY
3333
X-Request-Id:
34-
- 12fc57cb-d111-4bce-8998-535a2360fd24
34+
- cbfce925-94a9-46d6-9b31-27672a1fd1e9
3535
status: 200 OK
3636
code: 200
3737
duration: ""

0 commit comments

Comments
 (0)