Skip to content

Commit 71dc470

Browse files
authored
fix(vpcgw):add better vizualisation for gateway and IP (#3644)
1 parent e38f27a commit 71dc470

8 files changed

+713
-4
lines changed

internal/namespaces/vpcgw/v1/custom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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)
1415

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

internal/namespaces/vpcgw/v1/custom_gateway_network.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,23 @@ func gatewayNetworkCreateBuilder(c *core.Command) *core.Command {
3535
}
3636
return c
3737
}
38+
39+
func gatewayNetworkMarshallerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
40+
type tmp vpcgw.Gateway
41+
vpcgtwNetwork := tmp(i.(vpcgw.Gateway))
42+
opt.Sections = []*human.MarshalSection{
43+
{
44+
FieldName: "IP",
45+
Title: "IP",
46+
},
47+
{
48+
FieldName: "GatewayNetworks",
49+
Title: "GatewayNetworks",
50+
},
51+
}
52+
str, err := human.Marshal(vpcgtwNetwork, opt)
53+
if err != nil {
54+
return "", err
55+
}
56+
return str, nil
57+
}
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
version: 1
33
interactions:
44
- request:
5-
body: ""
5+
body: '{"types":[{"name":"VPC-GW-S", "bandwidth":100000000, "zone":"fr-par-1"},
6+
{"name":"VPC-GW-M", "bandwidth":1000000000, "zone":"fr-par-1"}]}'
67
form: {}
78
headers:
89
User-Agent:
9-
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.5; darwin; amd64) cli-e2e-test
10+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test
1011
url: https://api.scaleway.com/vpc-gw/v1/zones/fr-par-1/gateway-types
1112
method: GET
1213
response:
@@ -20,7 +21,7 @@ interactions:
2021
Content-Type:
2122
- application/json
2223
Date:
23-
- Tue, 28 Mar 2023 13:19:36 GMT
24+
- Fri, 09 Feb 2024 10:04:35 GMT
2425
Server:
2526
- Scaleway API-Gateway
2627
Strict-Transport-Security:
@@ -30,7 +31,7 @@ interactions:
3031
X-Frame-Options:
3132
- DENY
3233
X-Request-Id:
33-
- 623afde2-5a9d-4c65-953d-0331be842ae5
34+
- 12fc57cb-d111-4bce-8998-535a2360fd24
3435
status: 200 OK
3536
code: 200
3637
duration: ""

0 commit comments

Comments
 (0)