From 3fa2efa69f34bca2d40456a3ecb4903a91f7a89e Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Mon, 13 Jul 2020 16:44:11 +0200 Subject: [PATCH 1/4] fix(rdb): fix instance listing output --- internal/human/marshal.go | 4 +++- internal/human/specs.go | 3 +++ internal/namespaces/rdb/v1/custom_instance.go | 20 ++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/internal/human/marshal.go b/internal/human/marshal.go index c15ae41048..7a88076fcc 100644 --- a/internal/human/marshal.go +++ b/internal/human/marshal.go @@ -264,6 +264,8 @@ func marshalSlice(slice reflect.Value, opt *MarshalOpt) (string, error) { opt.Fields = getDefaultFieldsOpt(itemType) } + subOpts := &MarshalOpt{TableCell: true} + // Validate that all field exist for _, f := range opt.Fields { _, err := gofields.GetType(itemType, f.FieldName) @@ -304,7 +306,7 @@ func marshalSlice(slice reflect.Value, opt *MarshalOpt) (string, error) { case fieldValue.Type().Kind() == reflect.Slice: str, err = marshalInlineSlice(fieldValue) default: - str, err = Marshal(fieldValue.Interface(), opt) + str, err = Marshal(fieldValue.Interface(), subOpts) } if err != nil { return "", err diff --git a/internal/human/specs.go b/internal/human/specs.go index 8ee7d78a2b..ee640e2504 100644 --- a/internal/human/specs.go +++ b/internal/human/specs.go @@ -11,6 +11,9 @@ type MarshalOpt struct { Title string Fields []*MarshalFieldOpt Sections []*MarshalSection + + // Is set to true if we are marshaling a table cell + TableCell bool } type MarshalFieldOpt struct { diff --git a/internal/namespaces/rdb/v1/custom_instance.go b/internal/namespaces/rdb/v1/custom_instance.go index 610969cfe7..17bfb66dc8 100644 --- a/internal/namespaces/rdb/v1/custom_instance.go +++ b/internal/namespaces/rdb/v1/custom_instance.go @@ -57,6 +57,16 @@ func instanceMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) } func backupScheduleMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) { + backupSchedule := i.(rdb.BackupSchedule) + + if opt.TableCell { + if backupSchedule.Disabled { + return "Disabled", nil + } else { + return "Enabled", nil + } + } + // To avoid recursion of human.Marshal we create a dummy type type LocalBackupSchedule rdb.BackupSchedule type tmp struct { @@ -65,17 +75,17 @@ func backupScheduleMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, Retention *scw.Duration `json:"retention"` } - backupSchedule := tmp{ - LocalBackupSchedule: LocalBackupSchedule(i.(rdb.BackupSchedule)), + localBackupSchedule := tmp{ + LocalBackupSchedule: LocalBackupSchedule(backupSchedule), Frequency: &scw.Duration{ - Seconds: int64(i.(rdb.BackupSchedule).Frequency) * 3600, + Seconds: int64(backupSchedule.Frequency) * 3600, }, Retention: &scw.Duration{ - Seconds: int64(i.(rdb.BackupSchedule).Retention) * 24 * 3600, + Seconds: int64(backupSchedule.Retention) * 24 * 3600, }, } - str, err := human.Marshal(backupSchedule, opt) + str, err := human.Marshal(localBackupSchedule, opt) if err != nil { return "", err } From 3b2cd25fa96d9cdcbb75f836820bc784a84d457f Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Mon, 13 Jul 2020 17:04:08 +0200 Subject: [PATCH 2/4] add test --- .../namespaces/rdb/v1/custom_instance_test.go | 10 + .../test-list-instance-simple.cassette.yaml | 517 ++++++++++++++++++ .../testdata/test-list-instance-simple.golden | 60 ++ 3 files changed, 587 insertions(+) create mode 100644 internal/namespaces/rdb/v1/testdata/test-list-instance-simple.cassette.yaml create mode 100644 internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden diff --git a/internal/namespaces/rdb/v1/custom_instance_test.go b/internal/namespaces/rdb/v1/custom_instance_test.go index 7c07c8949d..5a5a06017e 100644 --- a/internal/namespaces/rdb/v1/custom_instance_test.go +++ b/internal/namespaces/rdb/v1/custom_instance_test.go @@ -7,6 +7,16 @@ import ( "github.com/scaleway/scaleway-cli/internal/core" ) +func Test_ListInstance(t *testing.T) { + t.Run("Simple", core.Test(&core.TestConfig{ + Commands: GetCommands(), + BeforeFunc: createInstance("PostgreSQL-12"), + Cmd: "scw rdb instance list", + Check: core.TestCheckGolden(), + AfterFunc: deleteInstance(), + })) +} + func Test_CloneInstance(t *testing.T) { t.Run("Simple", core.Test(&core.TestConfig{ Commands: GetCommands(), diff --git a/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.cassette.yaml b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.cassette.yaml new file mode 100644 index 0000000000..34ab0d6029 --- /dev/null +++ b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.cassette.yaml @@ -0,0 +1,517 @@ +--- +version: 1 +interactions: +- request: + body: '{"organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","name":"cli-test","engine":"PostgreSQL-12","user_name":"foobar","password":"{4xdl*#QOoP+\u00263XRkGA)]","node_type":"db-dev-s","is_ha_cluster":false,"disable_backup":false,"tags":null}' + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances + method: POST + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"provisioning","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:52:13 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 01ba91ce-55b9-4ceb-a863-395ca643c35c + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"provisioning","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:52:13 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 816e3e95-a404-4e2c-a343-5458af48ddaf + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"provisioning","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:52:28 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - fd3b2241-dede-401d-95f6-a43bb2cd45cc + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"provisioning","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:52:44 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 111523e7-c9aa-4897-bb8c-d838409c90f7 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"provisioning","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:52:59 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 21264140-a0a6-413c-991b-681387a51c8a + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:53:14 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 9090afdc-672b-4982-a8e8-13fafe148197 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:53:29 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - d45d1965-8083-40a9-a6cc-f5b2466f9a70 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:53:44 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 14c88fa0-897f-47b0-a5f4-c102585813fc + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:53:59 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - aa6fcbef-3532-44a4-86a5-375ebb7fe06c + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:54:14 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 45b7c496-3fb3-4d64-a861-eb53f84716b1 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:54:29 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 93ea811a-c67c-462f-841e-ac2077bf0c1c + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:54:44 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - ac322a62-ae64-4c18-8b80-81f302c31c72 + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"initializing","engine":"PostgreSQL-12","endpoint":null,"tags":[],"settings":[],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "443" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:54:59 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - be8705f1-fc66-401a-8120-8893d2f7fbca + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: GET + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"ready","engine":"PostgreSQL-12","endpoint":{"ip":"195.154.71.31","port":36723,"name":null},"tags":[],"settings":[{"name":"work_mem","value":"4"},{"name":"max_connections","value":"100"},{"name":"effective_cache_size","value":"1300"},{"name":"maintenance_work_mem","value":"150"},{"name":"max_parallel_workers","value":"0"},{"name":"max_parallel_workers_per_gather","value":"0"}],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "743" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:55:14 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 6724e2ac-882a-40ce-bf84-7c95742de8bf + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances?order_by=created_at_asc&page=1 + method: GET + response: + body: '{"instances":[{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"ready","engine":"PostgreSQL-12","endpoint":{"ip":"195.154.71.31","port":36723,"name":null},"tags":[],"settings":[{"name":"work_mem","value":"4"},{"name":"max_connections","value":"100"},{"name":"effective_cache_size","value":"1300"},{"name":"maintenance_work_mem","value":"150"},{"name":"max_parallel_workers","value":"0"},{"name":"max_parallel_workers_per_gather","value":"0"}],"backup_schedule":{"frequency":24,"retention":7,"disabled":false},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}],"total_count":1}' + headers: + Content-Length: + - "775" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:55:14 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - 1380a912-a834-48d9-9040-019f8cccca8e + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + User-Agent: + - scaleway-sdk-go/v1.0.0-beta.6+dev (go1.14.4; darwin; amd64) cli-e2e-test + url: https://api.scaleway.com/rdb/v1/regions/fr-par/instances/173121d7-13cc-47ab-9b19-98856cf8a30e + method: DELETE + response: + body: '{"id":"173121d7-13cc-47ab-9b19-98856cf8a30e","name":"cli-test","organization_id":"b3ba839a-dcf2-4b0a-ac81-fc32370052a0","status":"deleting","engine":"PostgreSQL-12","endpoint":{"ip":"195.154.71.31","port":36723,"name":null},"tags":[],"settings":[{"name":"work_mem","value":"4"},{"name":"max_connections","value":"100"},{"name":"effective_cache_size","value":"1300"},{"name":"maintenance_work_mem","value":"150"},{"name":"max_parallel_workers","value":"0"},{"name":"max_parallel_workers_per_gather","value":"0"}],"backup_schedule":{"frequency":24,"retention":7,"disabled":true},"is_ha_cluster":false,"read_replicas":[],"node_type":"db-dev-s","volume":{"type":"lssd","size":5000000000},"created_at":"2020-07-13T14:52:13.228258Z","region":"fr-par"}' + headers: + Content-Length: + - "745" + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 13 Jul 2020 14:55:17 GMT + Server: + - agw_listener_public_vip + Strict-Transport-Security: + - max-age=63072000 + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Request-Id: + - c781365c-c22d-4014-8316-3b1e770e84e4 + status: 200 OK + code: 200 + duration: "" diff --git a/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden new file mode 100644 index 0000000000..35249952c3 --- /dev/null +++ b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden @@ -0,0 +1,60 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +🟩🟩🟩 STDOUT️ 🟩🟩🟩️ +CREATED AT REGION ID NAME ORGANIZATION ID STATUS ENGINE TAGS SETTINGS BACKUP SCHEDULE IS HA CLUSTER READ REPLICAS NODE TYPE +few seconds ago fr-par 173121d7-13cc-47ab-9b19-98856cf8a30e cli-test b3ba839a-dcf2-4b0a-ac81-fc32370052a0 ready PostgreSQL-12 [] 6 Enabled false 0 db-dev-s +🟩🟩🟩 JSON STDOUT 🟩🟩🟩 +[ + { + "created_at": "1970-01-01T00:00:00.0Z", + "volume": { + "type": "lssd", + "size": 5000000000 + }, + "region": "fr-par", + "id": "173121d7-13cc-47ab-9b19-98856cf8a30e", + "name": "cli-test", + "organization_id": "b3ba839a-dcf2-4b0a-ac81-fc32370052a0", + "status": "ready", + "engine": "PostgreSQL-12", + "endpoint": { + "ip": "195.154.71.31", + "port": 36723, + "name": null + }, + "tags": [], + "settings": [ + { + "name": "work_mem", + "value": "4" + }, + { + "name": "max_connections", + "value": "100" + }, + { + "name": "effective_cache_size", + "value": "1300" + }, + { + "name": "maintenance_work_mem", + "value": "150" + }, + { + "name": "max_parallel_workers", + "value": "0" + }, + { + "name": "max_parallel_workers_per_gather", + "value": "0" + } + ], + "backup_schedule": { + "frequency": 24, + "retention": 7, + "disabled": false + }, + "is_ha_cluster": false, + "read_replicas": [], + "node_type": "db-dev-s" + } +] From 328d4e615106612d3cf0a12e450d9844248b2b9b Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Mon, 13 Jul 2020 17:21:26 +0200 Subject: [PATCH 3/4] lint --- internal/namespaces/rdb/v1/custom_instance.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/namespaces/rdb/v1/custom_instance.go b/internal/namespaces/rdb/v1/custom_instance.go index 17bfb66dc8..dd1f1074cf 100644 --- a/internal/namespaces/rdb/v1/custom_instance.go +++ b/internal/namespaces/rdb/v1/custom_instance.go @@ -62,9 +62,8 @@ func backupScheduleMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, if opt.TableCell { if backupSchedule.Disabled { return "Disabled", nil - } else { - return "Enabled", nil } + return "Enabled", nil } // To avoid recursion of human.Marshal we create a dummy type From efc61e16e3b3aaffd874eee61780019864a36393 Mon Sep 17 00:00:00 2001 From: Jerome Quere Date: Wed, 15 Jul 2020 13:37:28 +0200 Subject: [PATCH 4/4] golden --- .../rdb/v1/testdata/test-list-instance-simple.golden | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden index 35249952c3..7369098200 100644 --- a/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden +++ b/internal/namespaces/rdb/v1/testdata/test-list-instance-simple.golden @@ -1,7 +1,7 @@ 🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 🟩🟩🟩 STDOUT️ 🟩🟩🟩️ -CREATED AT REGION ID NAME ORGANIZATION ID STATUS ENGINE TAGS SETTINGS BACKUP SCHEDULE IS HA CLUSTER READ REPLICAS NODE TYPE -few seconds ago fr-par 173121d7-13cc-47ab-9b19-98856cf8a30e cli-test b3ba839a-dcf2-4b0a-ac81-fc32370052a0 ready PostgreSQL-12 [] 6 Enabled false 0 db-dev-s +ID NAME NODE TYPE STATUS ENGINE REGION TAGS IS HA CLUSTER BACKUP SCHEDULE CREATED AT +173121d7-13cc-47ab-9b19-98856cf8a30e cli-test db-dev-s ready PostgreSQL-12 fr-par [] false Enabled few seconds ago 🟩🟩🟩 JSON STDOUT 🟩🟩🟩 [ {