Skip to content

Commit

Permalink
feat(config store): adds ListConfigStoresInput when returning ListCon…
Browse files Browse the repository at this point in the history
…figStores (#481)

The addition of the ListConfigStoresInput allows for using the `name` param when retrieving a list of config stores.
  • Loading branch information
stevendaniels authored Nov 15, 2023
1 parent dbe29c1 commit 8c73791
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
19 changes: 16 additions & 3 deletions fastly/config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 16 additions & 2 deletions fastly/config_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
})
Expand All @@ -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 {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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: ""

0 comments on commit 8c73791

Please sign in to comment.