From ed5baeba1def7cacbf5aa04b8ffa306ce2c79a6e Mon Sep 17 00:00:00 2001 From: Yacine FODIL Date: Tue, 28 Mar 2023 14:35:11 +0200 Subject: [PATCH] feat(webhosting): improve offer list visualization --- .../namespaces/webhosting/v1alpha1/custom.go | 2 + .../webhosting/v1alpha1/custom_offer.go | 17 +++ .../webhosting/v1alpha1/custom_offer_test.go | 15 +++ .../test-list-offer-simple.cassette.yaml | 55 ++++++++ .../testdata/test-list-offer-simple.golden | 124 ++++++++++++++++++ 5 files changed, 213 insertions(+) create mode 100644 internal/namespaces/webhosting/v1alpha1/custom_offer.go create mode 100644 internal/namespaces/webhosting/v1alpha1/custom_offer_test.go create mode 100644 internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.cassette.yaml create mode 100644 internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.golden diff --git a/internal/namespaces/webhosting/v1alpha1/custom.go b/internal/namespaces/webhosting/v1alpha1/custom.go index 71ce42fa91..7f8408fa5d 100644 --- a/internal/namespaces/webhosting/v1alpha1/custom.go +++ b/internal/namespaces/webhosting/v1alpha1/custom.go @@ -13,5 +13,7 @@ func GetCommands() *core.Commands { human.RegisterMarshalerFunc(webhosting.DNSRecordsStatus(""), human.EnumMarshalFunc(hostingDNSMarshalSpecs)) human.RegisterMarshalerFunc(webhosting.NameserverStatus(""), human.EnumMarshalFunc(nameserverMarshalSpecs)) + cmds.MustFind("webhosting", "offer", "list").Override(webhostingOfferListBuilder) + return cmds } diff --git a/internal/namespaces/webhosting/v1alpha1/custom_offer.go b/internal/namespaces/webhosting/v1alpha1/custom_offer.go new file mode 100644 index 0000000000..411c8a86da --- /dev/null +++ b/internal/namespaces/webhosting/v1alpha1/custom_offer.go @@ -0,0 +1,17 @@ +package webhosting + +import "github.com/scaleway/scaleway-cli/v2/internal/core" + +func webhostingOfferListBuilder(c *core.Command) *core.Command { + c.View = &core.View{ + Sections: []*core.ViewSection{ + + { + FieldName: "Offers", + Title: "Offers", + }, + }, + } + + return c +} diff --git a/internal/namespaces/webhosting/v1alpha1/custom_offer_test.go b/internal/namespaces/webhosting/v1alpha1/custom_offer_test.go new file mode 100644 index 0000000000..82999e2774 --- /dev/null +++ b/internal/namespaces/webhosting/v1alpha1/custom_offer_test.go @@ -0,0 +1,15 @@ +package webhosting + +import ( + "testing" + + "github.com/scaleway/scaleway-cli/v2/internal/core" +) + +func Test_ListOffer(t *testing.T) { + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + Cmd: "scw webhosting offer list", + Check: core.TestCheckGolden(), + })) +} diff --git a/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.cassette.yaml b/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.cassette.yaml new file mode 100644 index 0000000000..d2c4c36814 --- /dev/null +++ b/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.cassette.yaml @@ -0,0 +1,55 @@ +--- +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/webhosting/v1alpha1/regions/fr-par/offers?only_options=false&order_by=price_asc&without_options=false + method: GET + response: + body: '{"offers":[{"id":"e500237a-a9e9-11ec-b909-0242ac120002", "billing_operation_path":"/webhosting/backup/fr-par", + "product":{"name":"backup", "option":true, "email_accounts_quota":0, "email_storage_quota":0, + "databases_quota":0, "hosting_storage_quota":0, "support_included":false, "v_cpu":0, + "ram":0}, "price":{"currency_code":"EUR", "units":2, "nanos":990000000}, "available":true, + "quota_warnings":[]}, {"id":"f5c2ae8f-7625-4bca-b711-b44bb3d08694", "billing_operation_path":"/webhosting/lite/fr-par", + "product":{"name":"lite", "option":false, "email_accounts_quota":1, "email_storage_quota":5, + "databases_quota":1, "hosting_storage_quota":10, "support_included":true, "v_cpu":1, + "ram":1}, "price":{"currency_code":"EUR", "units":5, "nanos":990000000}, "available":true, + "quota_warnings":[]}, {"id":"d86c61a0-a9e9-11ec-b909-0242ac120002", "billing_operation_path":"/webhosting/personal/fr-par", + "product":{"name":"essential", "option":false, "email_accounts_quota":2, "email_storage_quota":5, + "databases_quota":-1, "hosting_storage_quota":50, "support_included":true, "v_cpu":2, + "ram":1}, "price":{"currency_code":"EUR", "units":9, "nanos":990000000}, "available":true, + "quota_warnings":[]}, {"id":"de2426b4-a9e9-11ec-b909-0242ac120002", "billing_operation_path":"/webhosting/professional/fr-par", + "product":{"name":"performance", "option":false, "email_accounts_quota":10, + "email_storage_quota":5, "databases_quota":-1, "hosting_storage_quota":100, + "support_included":true, "v_cpu":4, "ram":2}, "price":{"currency_code":"EUR", + "units":18, "nanos":990000000}, "available":true, "quota_warnings":[]}, {"id":"e1c1e6c6-a9e9-11ec-b909-0242ac120002", + "billing_operation_path":"/webhosting/ecommerce/fr-par", "product":{"name":"ecommerce", + "option":false, "email_accounts_quota":25, "email_storage_quota":5, "databases_quota":-1, + "hosting_storage_quota":250, "support_included":true, "v_cpu":8, "ram":8}, "price":{"currency_code":"EUR", + "units":29, "nanos":990000000}, "available":true, "quota_warnings":[]}]}' + headers: + Content-Length: + - "2002" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 28 Mar 2023 12:32:25 GMT + Server: + - Scaleway API-Gateway + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - d471ce2b-9726-4f8a-9518-4112558dc493 + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.golden b/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.golden new file mode 100644 index 0000000000..b7bfce9c67 --- /dev/null +++ b/internal/namespaces/webhosting/v1alpha1/testdata/test-list-offer-simple.golden @@ -0,0 +1,124 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 STDOUT️ 🟩🟩🟩️ +Offers: +ID BILLING OPERATION PATH PRICE AVAILABLE QUOTA WARNINGS +e500237a-a9e9-11ec-b909-0242ac120002 /webhosting/backup/fr-par € 2.99 true [] +f5c2ae8f-7625-4bca-b711-b44bb3d08694 /webhosting/lite/fr-par € 5.99 true [] +d86c61a0-a9e9-11ec-b909-0242ac120002 /webhosting/personal/fr-par € 9.99 true [] +de2426b4-a9e9-11ec-b909-0242ac120002 /webhosting/professional/fr-par € 18.99 true [] +e1c1e6c6-a9e9-11ec-b909-0242ac120002 /webhosting/ecommerce/fr-par € 29.99 true [] +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +{ + "offers": [ + { + "id": "e500237a-a9e9-11ec-b909-0242ac120002", + "billing_operation_path": "/webhosting/backup/fr-par", + "product": { + "name": "backup", + "option": true, + "email_accounts_quota": 0, + "email_storage_quota": 0, + "databases_quota": 0, + "hosting_storage_quota": 0, + "support_included": false, + "v_cpu": 0, + "ram": 0 + }, + "price": { + "currency_code": "EUR", + "units": 2, + "nanos": 990000000 + }, + "available": true, + "quota_warnings": [] + }, + { + "id": "f5c2ae8f-7625-4bca-b711-b44bb3d08694", + "billing_operation_path": "/webhosting/lite/fr-par", + "product": { + "name": "lite", + "option": false, + "email_accounts_quota": 1, + "email_storage_quota": 5, + "databases_quota": 1, + "hosting_storage_quota": 10, + "support_included": true, + "v_cpu": 1, + "ram": 1 + }, + "price": { + "currency_code": "EUR", + "units": 5, + "nanos": 990000000 + }, + "available": true, + "quota_warnings": [] + }, + { + "id": "d86c61a0-a9e9-11ec-b909-0242ac120002", + "billing_operation_path": "/webhosting/personal/fr-par", + "product": { + "name": "essential", + "option": false, + "email_accounts_quota": 2, + "email_storage_quota": 5, + "databases_quota": -1, + "hosting_storage_quota": 50, + "support_included": true, + "v_cpu": 2, + "ram": 1 + }, + "price": { + "currency_code": "EUR", + "units": 9, + "nanos": 990000000 + }, + "available": true, + "quota_warnings": [] + }, + { + "id": "de2426b4-a9e9-11ec-b909-0242ac120002", + "billing_operation_path": "/webhosting/professional/fr-par", + "product": { + "name": "performance", + "option": false, + "email_accounts_quota": 10, + "email_storage_quota": 5, + "databases_quota": -1, + "hosting_storage_quota": 100, + "support_included": true, + "v_cpu": 4, + "ram": 2 + }, + "price": { + "currency_code": "EUR", + "units": 18, + "nanos": 990000000 + }, + "available": true, + "quota_warnings": [] + }, + { + "id": "e1c1e6c6-a9e9-11ec-b909-0242ac120002", + "billing_operation_path": "/webhosting/ecommerce/fr-par", + "product": { + "name": "ecommerce", + "option": false, + "email_accounts_quota": 25, + "email_storage_quota": 5, + "databases_quota": -1, + "hosting_storage_quota": 250, + "support_included": true, + "v_cpu": 8, + "ram": 8 + }, + "price": { + "currency_code": "EUR", + "units": 29, + "nanos": 990000000 + }, + "available": true, + "quota_warnings": [] + } + ] +}