Skip to content

Commit

Permalink
fix(vpcgw):add better vizualisation for gateway and IP (#3644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di authored Feb 15, 2024
1 parent e38f27a commit 71dc470
Show file tree
Hide file tree
Showing 8 changed files with 713 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/namespaces/vpcgw/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func GetCommands() *core.Commands {

human.RegisterMarshalerFunc(vpcgw.GatewayNetworkStatus(""), human.EnumMarshalFunc(gatewayNetworkStatusMarshalSpecs))
human.RegisterMarshalerFunc(vpcgw.GatewayStatus(""), human.EnumMarshalFunc(gatewayStatusMarshalSpecs))
human.RegisterMarshalerFunc(vpcgw.Gateway{}, gatewayNetworkMarshallerFunc)

cmds.MustFind("vpc-gw", "gateway-type", "list").Override(vpcgwGatewayTypeListBuilder)
cmds.MustFind("vpc-gw", "gateway", "create").Override(gatewayCreateBuilder)
Expand Down
20 changes: 20 additions & 0 deletions internal/namespaces/vpcgw/v1/custom_gateway_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,23 @@ func gatewayNetworkCreateBuilder(c *core.Command) *core.Command {
}
return c
}

func gatewayNetworkMarshallerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp vpcgw.Gateway
vpcgtwNetwork := tmp(i.(vpcgw.Gateway))
opt.Sections = []*human.MarshalSection{
{
FieldName: "IP",
Title: "IP",
},
{
FieldName: "GatewayNetworks",
Title: "GatewayNetworks",
},
}
str, err := human.Marshal(vpcgtwNetwork, opt)
if err != nil {
return "", err
}
return str, nil
}
31 changes: 31 additions & 0 deletions internal/namespaces/vpcgw/v1/custom_gateway_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package vpcgw

import (
"testing"

"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/namespaces/vpc/v2"
"github.com/scaleway/scaleway-cli/v2/internal/testhelpers"
)

func Test_vpcGwGatewayGet(t *testing.T) {
cmds := GetCommands()
cmds.Merge(vpc.GetCommands())

t.Run("Simple", core.Test(&core.TestConfig{
Commands: cmds,
BeforeFunc: core.BeforeFuncCombine(
testhelpers.CreatePN(),
testhelpers.CreateGateway("GW"),
testhelpers.CreateGatewayNetwork("GW"),
),
Cmd: "scw vpc-gw gateway get {{ .GW.ID }}",
Check: core.TestCheckGolden(),
AfterFunc: core.AfterFuncCombine(
testhelpers.DeleteGatewayNetwork(),
testhelpers.DeletePN(),
testhelpers.DeleteGateway("GW"),
testhelpers.DeleteIPVpcGw("GW"),
),
}))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
version: 1
interactions:
- request:
body: ""
body: '{"types":[{"name":"VPC-GW-S", "bandwidth":100000000, "zone":"fr-par-1"},
{"name":"VPC-GW-M", "bandwidth":1000000000, "zone":"fr-par-1"}]}'
form: {}
headers:
User-Agent:
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.5; darwin; amd64) cli-e2e-test
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.21.5; darwin; amd64) cli-e2e-test
url: https://api.scaleway.com/vpc-gw/v1/zones/fr-par-1/gateway-types
method: GET
response:
Expand All @@ -20,7 +21,7 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Mar 2023 13:19:36 GMT
- Fri, 09 Feb 2024 10:04:35 GMT
Server:
- Scaleway API-Gateway
Strict-Transport-Security:
Expand All @@ -30,7 +31,7 @@ interactions:
X-Frame-Options:
- DENY
X-Request-Id:
- 623afde2-5a9d-4c65-953d-0331be842ae5
- 12fc57cb-d111-4bce-8998-535a2360fd24
status: 200 OK
code: 200
duration: ""
Loading

0 comments on commit 71dc470

Please sign in to comment.