-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config_store): implement batch endpoint (#444)
- Loading branch information
1 parent
52d2658
commit 41eb1ff
Showing
7 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package fastly | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestClient_ConfigStoreBatch(t *testing.T) { | ||
t.Parallel() | ||
|
||
cs := createConfigStoreForBatch(t) | ||
|
||
var err error | ||
|
||
record(t, "config_store_batch/create_and_upsert", func(c *Client) { | ||
err = c.BatchModifyConfigStoreItems(&BatchModifyConfigStoreItemsInput{ | ||
StoreID: cs.ID, | ||
Items: []*BatchConfigStoreItem{ | ||
{ | ||
ItemKey: "key1", | ||
ItemValue: "value1", | ||
Operation: CreateBatchOperation, | ||
}, | ||
{ | ||
ItemKey: "key2", | ||
ItemValue: "value2", | ||
Operation: UpsertBatchOperation, | ||
}, | ||
}, | ||
}) | ||
}) | ||
if err != nil { | ||
t.Fatalf("error batch creating config store items: %v", err) | ||
} | ||
|
||
record(t, "config_store_batch/update_and_upsert", func(c *Client) { | ||
err = c.BatchModifyConfigStoreItems(&BatchModifyConfigStoreItemsInput{ | ||
StoreID: cs.ID, | ||
Items: []*BatchConfigStoreItem{ | ||
{ | ||
ItemKey: "key1", | ||
ItemValue: "value2", | ||
Operation: UpdateBatchOperation, | ||
}, | ||
{ | ||
ItemKey: "key2", | ||
ItemValue: "value3", | ||
Operation: UpsertBatchOperation, | ||
}, | ||
}, | ||
}) | ||
}) | ||
if err != nil { | ||
t.Fatalf("error batch updating config store items: %v", err) | ||
} | ||
|
||
record(t, "config_store_batch/delete", func(c *Client) { | ||
err = c.BatchModifyConfigStoreItems(&BatchModifyConfigStoreItemsInput{ | ||
StoreID: cs.ID, | ||
Items: []*BatchConfigStoreItem{ | ||
{ | ||
ItemKey: "key1", | ||
Operation: DeleteBatchOperation, | ||
}, | ||
{ | ||
ItemKey: "key2", | ||
Operation: DeleteBatchOperation, | ||
}, | ||
}, | ||
}) | ||
}) | ||
if err != nil { | ||
t.Fatalf("error batch deleting config store items: %v", err) | ||
} | ||
} | ||
|
||
func createConfigStoreForBatch(t *testing.T) *ConfigStore { | ||
t.Helper() | ||
|
||
var ( | ||
cs *ConfigStore | ||
err error | ||
) | ||
record(t, fmt.Sprintf("config_store_batch/%s/create_store", t.Name()), func(c *Client) { | ||
cs, err = c.CreateConfigStore(&CreateConfigStoreInput{ | ||
Name: t.Name(), | ||
}) | ||
}) | ||
if err != nil { | ||
t.Fatalf("error creating config store: %v", err) | ||
} | ||
|
||
// Ensure Config Store is cleaned up. | ||
t.Cleanup(func() { | ||
record(t, fmt.Sprintf("config_store_batch/%s/delete_store", t.Name()), func(c *Client) { | ||
err = c.DeleteConfigStore(&DeleteConfigStoreInput{ | ||
ID: cs.ID, | ||
}) | ||
}) | ||
if err != nil { | ||
t.Fatalf("error deleting config store %q: %v", cs.ID, err) | ||
} | ||
}) | ||
|
||
return cs | ||
} |
51 changes: 51 additions & 0 deletions
51
fastly/fixtures/config_store_batch/TestClient_ConfigStoreBatch/create_store.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: name=TestClient_ConfigStoreBatch | ||
form: | ||
name: | ||
- TestClient_ConfigStoreBatch | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/x-www-form-urlencoded | ||
User-Agent: | ||
- FastlyGo/8.4.1 (+github.com/fastly/go-fastly; go1.18.5) | ||
url: https://api.fastly.com/resources/stores/config | ||
method: POST | ||
response: | ||
body: '{"name":"TestClient_ConfigStoreBatch","id":"LO53FrkHHmWWropCH2ICN2","created_at":"2023-06-07T16:29:19Z","updated_at":"2023-06-07T16:29:19Z","deleted_at":null}' | ||
headers: | ||
Accept-Ranges: | ||
- bytes | ||
Cache-Control: | ||
- no-store | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 07 Jun 2023 16:29:19 GMT | ||
Fastly-Ratelimit-Remaining: | ||
- "9999" | ||
Fastly-Ratelimit-Reset: | ||
- "1686157200" | ||
Status: | ||
- 200 OK | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Accept-Encoding | ||
Via: | ||
- 1.1 varnish, 1.1 varnish | ||
X-Cache: | ||
- MISS, MISS | ||
X-Cache-Hits: | ||
- 0, 0 | ||
X-Served-By: | ||
- cache-control-cp-aws-us-east-2-prod-6-CONTROL-AWS-UE2, cache-lhr7336-LHR | ||
X-Timer: | ||
- S1686155360.565387,VS0,VE166 | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
47 changes: 47 additions & 0 deletions
47
fastly/fixtures/config_store_batch/TestClient_ConfigStoreBatch/delete_store.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: "" | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
User-Agent: | ||
- FastlyGo/8.4.1 (+github.com/fastly/go-fastly; go1.18.5) | ||
url: https://api.fastly.com/resources/stores/config/LO53FrkHHmWWropCH2ICN2 | ||
method: DELETE | ||
response: | ||
body: '{"status":"ok"}' | ||
headers: | ||
Accept-Ranges: | ||
- bytes | ||
Cache-Control: | ||
- no-store | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 07 Jun 2023 16:29:20 GMT | ||
Fastly-Ratelimit-Remaining: | ||
- "9995" | ||
Fastly-Ratelimit-Reset: | ||
- "1686157200" | ||
Status: | ||
- 200 OK | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Accept-Encoding | ||
Via: | ||
- 1.1 varnish, 1.1 varnish | ||
X-Cache: | ||
- MISS, MISS | ||
X-Cache-Hits: | ||
- 0, 0 | ||
X-Served-By: | ||
- cache-control-cp-aws-us-east-2-prod-7-CONTROL-AWS-UE2, cache-lhr7336-LHR | ||
X-Timer: | ||
- S1686155360.335549,VS0,VE173 | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: '{"items":[{"item_key":"key1","item_value":"value1","op":"create"},{"item_key":"key2","item_value":"value2","op":"upsert"}]}' | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- FastlyGo/8.4.1 (+github.com/fastly/go-fastly; go1.18.5) | ||
url: https://api.fastly.com/resources/stores/config/LO53FrkHHmWWropCH2ICN2/items | ||
method: PATCH | ||
response: | ||
body: '{"status":"ok"}' | ||
headers: | ||
Accept-Ranges: | ||
- bytes | ||
Cache-Control: | ||
- no-store | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 07 Jun 2023 16:29:19 GMT | ||
Fastly-Ratelimit-Remaining: | ||
- "9998" | ||
Fastly-Ratelimit-Reset: | ||
- "1686157200" | ||
Status: | ||
- 200 OK | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Accept-Encoding | ||
Via: | ||
- 1.1 varnish, 1.1 varnish | ||
X-Cache: | ||
- MISS, MISS | ||
X-Cache-Hits: | ||
- 0, 0 | ||
X-Served-By: | ||
- cache-control-cp-aws-us-east-2-prod-7-CONTROL-AWS-UE2, cache-lhr7336-LHR | ||
X-Timer: | ||
- S1686155360.758050,VS0,VE153 | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: '{"items":[{"item_key":"key1","item_value":"","op":"delete"},{"item_key":"key2","item_value":"","op":"delete"}]}' | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- FastlyGo/8.4.1 (+github.com/fastly/go-fastly; go1.18.5) | ||
url: https://api.fastly.com/resources/stores/config/LO53FrkHHmWWropCH2ICN2/items | ||
method: PATCH | ||
response: | ||
body: '{"status":"ok"}' | ||
headers: | ||
Accept-Ranges: | ||
- bytes | ||
Cache-Control: | ||
- no-store | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 07 Jun 2023 16:29:20 GMT | ||
Fastly-Ratelimit-Remaining: | ||
- "9996" | ||
Fastly-Ratelimit-Reset: | ||
- "1686157200" | ||
Status: | ||
- 200 OK | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Accept-Encoding | ||
Via: | ||
- 1.1 varnish, 1.1 varnish | ||
X-Cache: | ||
- MISS, MISS | ||
X-Cache-Hits: | ||
- 0, 0 | ||
X-Served-By: | ||
- cache-control-cp-aws-us-east-2-prod-7-CONTROL-AWS-UE2, cache-lhr7336-LHR | ||
X-Timer: | ||
- S1686155360.153553,VS0,VE159 | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
version: 1 | ||
interactions: | ||
- request: | ||
body: '{"items":[{"item_key":"key1","item_value":"value2","op":"update"},{"item_key":"key2","item_value":"value3","op":"upsert"}]}' | ||
form: {} | ||
headers: | ||
Accept: | ||
- application/json | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- FastlyGo/8.4.1 (+github.com/fastly/go-fastly; go1.18.5) | ||
url: https://api.fastly.com/resources/stores/config/LO53FrkHHmWWropCH2ICN2/items | ||
method: PATCH | ||
response: | ||
body: '{"status":"ok"}' | ||
headers: | ||
Accept-Ranges: | ||
- bytes | ||
Cache-Control: | ||
- no-store | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 07 Jun 2023 16:29:20 GMT | ||
Fastly-Ratelimit-Remaining: | ||
- "9997" | ||
Fastly-Ratelimit-Reset: | ||
- "1686157200" | ||
Status: | ||
- 200 OK | ||
Strict-Transport-Security: | ||
- max-age=31536000 | ||
Vary: | ||
- Accept-Encoding | ||
Via: | ||
- 1.1 varnish, 1.1 varnish | ||
X-Cache: | ||
- MISS, MISS | ||
X-Cache-Hits: | ||
- 0, 0 | ||
X-Served-By: | ||
- cache-control-cp-aws-us-east-2-prod-6-CONTROL-AWS-UE2, cache-lhr7336-LHR | ||
X-Timer: | ||
- S1686155360.940372,VS0,VE176 | ||
status: 200 OK | ||
code: 200 | ||
duration: "" |