From 8af7257d0a6a8dc2f3aa657d515fc16f9c2782b5 Mon Sep 17 00:00:00 2001 From: Steven Daniels Date: Tue, 7 Nov 2023 13:10:27 -0500 Subject: [PATCH] feat(config store): adds ListConfigStoresInput when returning ListConfigStores The addition of the ListConfigStoresInput allows for using the `name` param when retrieving a list of config stores. --- fastly/config_store.go | 19 ++++++++++-- fastly/config_store_test.go | 18 ++++++++++-- .../list-with-name.yaml | 29 +++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 fastly/fixtures/config_store/TestClient_ListConfigStores/list-with-name.yaml diff --git a/fastly/config_store.go b/fastly/config_store.go index 12cf30c9d..4fab6a610 100644 --- a/fastly/config_store.go +++ b/fastly/config_store.go @@ -149,15 +149,28 @@ func (c *Client) GetConfigStoreMetadata(i *GetConfigStoreMetadataInput) (*Config return csm, nil } +// ListConfigStoreServicesInput is the input to ListConfigStoreServices. +type ListConfigStoresInput struct { + // Name is the name of a config store (optional). + Name string +} + // ListConfigStores returns a list of config stores sorted by name. -func (c *Client) ListConfigStores() ([]*ConfigStore, error) { +func (c *Client) ListConfigStores(i *ListConfigStoresInput) ([]*ConfigStore, error) { path := "/resources/stores/config" - resp, err := c.Get(path, &RequestOptions{ + + requestOptions := &RequestOptions{ Headers: map[string]string{ "Accept": "application/json", }, Parallel: true, - }) + } + + if i.Name != "" { + requestOptions.Params = map[string]string{"name": i.Name} + } + + resp, err := c.Get(path, requestOptions) if err != nil { return nil, err } diff --git a/fastly/config_store_test.go b/fastly/config_store_test.go index 74f911038..0079a1277 100644 --- a/fastly/config_store_test.go +++ b/fastly/config_store_test.go @@ -223,7 +223,7 @@ func TestClient_ListConfigStores(t *testing.T) { // Verify list works when there are no stores. record(t, fmt.Sprintf("config_store/%s/empty", t.Name()), func(c *Client) { - css, err = c.ListConfigStores() + css, err = c.ListConfigStores(&ListConfigStoresInput{}) }) if err != nil { t.Fatalf("ListConfigStores: unexpected error: %v", err) @@ -245,6 +245,7 @@ func TestClient_ListConfigStores(t *testing.T) { if err != nil { t.Fatalf("error creating config store: %v", err) } + t.Log(cs) stores = append(stores, cs) } }) @@ -263,7 +264,7 @@ func TestClient_ListConfigStores(t *testing.T) { }) record(t, fmt.Sprintf("config_store/%s/list", t.Name()), func(c *Client) { - css, err = c.ListConfigStores() + css, err = c.ListConfigStores(&ListConfigStoresInput{}) }) if got, want := len(css), len(stores); got != want { @@ -275,6 +276,19 @@ func TestClient_ListConfigStores(t *testing.T) { t.Errorf("ListConfigStores: index %d: ID: got %q, want %q", i, got, want) } } + + record(t, fmt.Sprintf("config_store/%s/list-with-name", t.Name()), func(c *Client) { + css, err = c.ListConfigStores(&ListConfigStoresInput{Name: stores[0].Name}) + }) + + if got, want := len(css), 1; got != want { + t.Fatalf("ListConfigStores: got %d entries, want %d", got, want) + } + + if got, want := css[0].ID, stores[0].ID; got != want { + t.Errorf("ListConfigStores: index %d: ID: got %q, want %q", 0, got, want) + } + } func TestClient_ListConfigStoreServices(t *testing.T) { diff --git a/fastly/fixtures/config_store/TestClient_ListConfigStores/list-with-name.yaml b/fastly/fixtures/config_store/TestClient_ListConfigStores/list-with-name.yaml new file mode 100644 index 000000000..577f3ca95 --- /dev/null +++ b/fastly/fixtures/config_store/TestClient_ListConfigStores/list-with-name.yaml @@ -0,0 +1,29 @@ +--- +version: 1 +interactions: + - request: + body: "" + form: {} + headers: + Accept: + - application/json + User-Agent: + - FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19) + url: https://api.fastly.com/resources/stores/config?name=TestClient_ListConfigStores-00 + method: GET + response: + body: '[{"name":"TestClient_ListConfigStores-00","id":"ykdY5UTyffIVUCF34jRcb2","created_at":"2023-03-01T22:12:15Z","updated_at":"2023-03-01T22:12:15Z","deleted_at":null}]' + headers: + Cache-Control: + - no-store + Content-Type: + - application/json + Date: + - Wed, 01 Mar 2023 22:12:17 GMT + Status: + - 200 OK + Vary: + - Accept-Encoding + status: 200 OK + code: 200 + duration: ""