Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config store): adds ListConfigStoresInput #481

Merged
merged 1 commit into from Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions fastly/config_store.go
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in a breaking interface change and a major release. Are we ok with doing that? If we're going to be pushing a breaking change we should check what else we can roll up into that release that is also breaking.

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
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
@@ -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: ""