From 836f0e10388ca439ef3f4c3200d1914b35c58288 Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Tue, 28 Mar 2023 14:49:07 +0200 Subject: [PATCH 1/2] feat(vpcgw): improve gateway-type list visualization --- internal/namespaces/vpcgw/v1/custom.go | 2 ++ .../vpcgw/v1/custom_gateway_type.go | 17 +++++++++ .../vpcgw/v1/custom_gateway_type_test.go | 15 ++++++++ ...est-list-gateway-type-simple.cassette.yaml | 36 +++++++++++++++++++ .../test-list-gateway-type-simple.golden | 21 +++++++++++ 5 files changed, 91 insertions(+) create mode 100644 internal/namespaces/vpcgw/v1/custom_gateway_type.go create mode 100644 internal/namespaces/vpcgw/v1/custom_gateway_type_test.go create mode 100644 internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml create mode 100644 internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden diff --git a/internal/namespaces/vpcgw/v1/custom.go b/internal/namespaces/vpcgw/v1/custom.go index 0ab451d0d0..fa44cd9959 100644 --- a/internal/namespaces/vpcgw/v1/custom.go +++ b/internal/namespaces/vpcgw/v1/custom.go @@ -12,5 +12,7 @@ func GetCommands() *core.Commands { human.RegisterMarshalerFunc(vpcgw.GatewayNetworkStatus(""), human.EnumMarshalFunc(gatewayNetworkStatusMarshalSpecs)) human.RegisterMarshalerFunc(vpcgw.GatewayStatus(""), human.EnumMarshalFunc(gatewayStatusMarshalSpecs)) + cmds.MustFind("vpc-gw", "gateway-type", "list").Override(vpcgwGatewayTypeListBuilder) + return cmds } diff --git a/internal/namespaces/vpcgw/v1/custom_gateway_type.go b/internal/namespaces/vpcgw/v1/custom_gateway_type.go new file mode 100644 index 0000000000..6c7d384c15 --- /dev/null +++ b/internal/namespaces/vpcgw/v1/custom_gateway_type.go @@ -0,0 +1,17 @@ +package vpcgw + +import "github.com/scaleway/scaleway-cli/v2/internal/core" + +func vpcgwGatewayTypeListBuilder(c *core.Command) *core.Command { + c.View = &core.View{ + Sections: []*core.ViewSection{ + + { + FieldName: "Types", + Title: "Types", + }, + }, + } + + return c +} diff --git a/internal/namespaces/vpcgw/v1/custom_gateway_type_test.go b/internal/namespaces/vpcgw/v1/custom_gateway_type_test.go new file mode 100644 index 0000000000..4d7bead8be --- /dev/null +++ b/internal/namespaces/vpcgw/v1/custom_gateway_type_test.go @@ -0,0 +1,15 @@ +package vpcgw + +import ( + "testing" + + "github.com/scaleway/scaleway-cli/v2/internal/core" +) + +func Test_ListGatewayType(t *testing.T) { + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + Cmd: "scw vpc-gw gateway-type list", + Check: core.TestCheckGolden(), + })) +} diff --git a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml new file mode 100644 index 0000000000..c9a1af2a86 --- /dev/null +++ b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml @@ -0,0 +1,36 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.7+dev (go1.19.5; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/vpc-gw/v1/zones/fr-par-1/gateway-types + method: GET + response: + body: '{"types":[{"name":"VPC-GW-S", "bandwidth":100000000, "zone":"fr-par-1"}, + {"name":"VPC-GW-M", "bandwidth":1000000000, "zone":"fr-par-1"}]}' + headers: + Content-Length: + - "137" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 28 Mar 2023 12:48:08 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - d23a2fd4-94cc-4bad-985f-a04b2e467ff6 + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden new file mode 100644 index 0000000000..b91f194254 --- /dev/null +++ b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden @@ -0,0 +1,21 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 STDOUT️ 🟩🟩🟩️ +Types: +NAME BANDWIDTH ZONE +VPC-GW-S 100000000 fr-par-1 +VPC-GW-M 1000000000 fr-par-1 +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +{ + "types": [ + { + "name": "VPC-GW-S", + "bandwidth": 100000000, + "zone": "fr-par-1" + }, + { + "name": "VPC-GW-M", + "bandwidth": 1000000000, + "zone": "fr-par-1" + } + ] +} From ed2097b803ce43d6109e6403c580735652a2089c Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Tue, 28 Mar 2023 15:20:24 +0200 Subject: [PATCH 2/2] fix --- .../vpcgw/v1/custom_gateway_type.go | 23 +++++++++------- ...est-list-gateway-type-simple.cassette.yaml | 4 +-- .../test-list-gateway-type-simple.golden | 27 +++++++++---------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/internal/namespaces/vpcgw/v1/custom_gateway_type.go b/internal/namespaces/vpcgw/v1/custom_gateway_type.go index 6c7d384c15..8ce1bc5b1f 100644 --- a/internal/namespaces/vpcgw/v1/custom_gateway_type.go +++ b/internal/namespaces/vpcgw/v1/custom_gateway_type.go @@ -1,17 +1,22 @@ package vpcgw -import "github.com/scaleway/scaleway-cli/v2/internal/core" +import ( + "context" + + "github.com/scaleway/scaleway-cli/v2/internal/core" + "github.com/scaleway/scaleway-sdk-go/api/vpcgw/v1" +) func vpcgwGatewayTypeListBuilder(c *core.Command) *core.Command { - c.View = &core.View{ - Sections: []*core.ViewSection{ + c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) { + res, err := runner(ctx, argsI) + if err != nil { + return nil, err + } - { - FieldName: "Types", - Title: "Types", - }, - }, - } + typesResponse := res.(*vpcgw.ListGatewayTypesResponse) + return typesResponse.Types, nil + }) return c } diff --git a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml index c9a1af2a86..0bed9b90a4 100644 --- a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml +++ b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.cassette.yaml @@ -20,7 +20,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 28 Mar 2023 12:48:08 GMT + - Tue, 28 Mar 2023 13:19:36 GMT Server: - Scaleway API-Gateway Strict-Transport-Security: @@ -30,7 +30,7 @@ interactions: X-Frame-Options: - DENY X-Request-Id: - - d23a2fd4-94cc-4bad-985f-a04b2e467ff6 + - 623afde2-5a9d-4c65-953d-0331be842ae5 status: 200 OK code: 200 duration: "" diff --git a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden index b91f194254..a1474e93f1 100644 --- a/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden +++ b/internal/namespaces/vpcgw/v1/testdata/test-list-gateway-type-simple.golden @@ -1,21 +1,18 @@ 🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 🟩🟩🟩 STDOUT️ 🟩🟩🟩️ -Types: NAME BANDWIDTH ZONE VPC-GW-S 100000000 fr-par-1 VPC-GW-M 1000000000 fr-par-1 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 -{ - "types": [ - { - "name": "VPC-GW-S", - "bandwidth": 100000000, - "zone": "fr-par-1" - }, - { - "name": "VPC-GW-M", - "bandwidth": 1000000000, - "zone": "fr-par-1" - } - ] -} +[ + { + "name": "VPC-GW-S", + "bandwidth": 100000000, + "zone": "fr-par-1" + }, + { + "name": "VPC-GW-M", + "bandwidth": 1000000000, + "zone": "fr-par-1" + } +]