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

Implement batch operations for dictionary items #125

Merged
merged 10 commits into from
Jul 22, 2019
Prev Previous commit
Next Next commit
Updates the BatchModifyDictionaryItemsInput items changed to pointers…
… and duplicates removed from fixtures.
  • Loading branch information
Trent Rosenbaum committed Jul 22, 2019
commit b5b369491181638672ff95c80ae831a0fc79fceb
2 changes: 1 addition & 1 deletion fastly/dictionary_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ type BatchModifyDictionaryItemsInput struct {
Service string `json:"-,"`
Dictionary string `json:"-,"`

Items []BatchDictionaryItem `json:"items"`
Items []*BatchDictionaryItem `json:"items"`
}

type BatchDictionaryItem struct {
Expand Down
58 changes: 29 additions & 29 deletions fastly/dictionary_item_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func TestClient_BatchModifyDictionaryItems_Create(t *testing.T) {
batchCreateOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Create,
ItemKey: "key1",
Operation: CreateBatchOperation,
ItemKey: "key1",
ItemValue: "val1",
},
{
Operation:Create,
ItemKey: "key2",
Operation: CreateBatchOperation,
ItemKey: "key2",
ItemValue: "val2",
},
},
Expand Down Expand Up @@ -100,15 +100,15 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) {
batchCreateOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Create,
ItemKey: "key1",
Operation: CreateBatchOperation,
ItemKey: "key1",
ItemValue: "val1",
},
{
Operation:Create,
ItemKey: "key2",
Operation: CreateBatchOperation,
ItemKey: "key2",
ItemValue: "val2",
},
},
Expand All @@ -127,10 +127,10 @@ func TestClient_BatchModifyDictionaryItems_Delete(t *testing.T) {
batchDeleteOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Delete,
ItemKey: "key2",
Operation: DeleteBatchOperation,
ItemKey: "key2",
ItemValue: "val2",
},
},
Expand Down Expand Up @@ -180,15 +180,15 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) {
batchCreateOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Create,
ItemKey: "key1",
Operation: CreateBatchOperation,
ItemKey: "key1",
ItemValue: "val1",
},
{
Operation:Create,
ItemKey: "key2",
Operation: CreateBatchOperation,
ItemKey: "key2",
ItemValue: "val2",
},
},
Expand All @@ -207,10 +207,10 @@ func TestClient_BatchModifyDictionaryItems_Update(t *testing.T) {
batchUpdateOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Update,
ItemKey: "key2",
Operation: UpdateBatchOperation,
ItemKey: "key2",
ItemValue: "val2Updated",
},
},
Expand Down Expand Up @@ -292,10 +292,10 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) {
batchCreateOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Create,
ItemKey: "key1",
Operation: CreateBatchOperation,
ItemKey: "key1",
ItemValue: "val1",
},
},
Expand All @@ -314,15 +314,15 @@ func TestClient_BatchModifyDictionaryItems_Upsert(t *testing.T) {
batchUpsertOperations := &BatchModifyDictionaryItemsInput {
Service: testService.ID,
Dictionary: testDictionary.ID,
Items: []BatchDictionaryItem{
Items: []*BatchDictionaryItem{
{
Operation:Upsert,
ItemKey: "key1",
Operation: UpsertBatchOperation,
ItemKey: "key1",
ItemValue: "val1Updated",
},
{
Operation:Upsert,
ItemKey: "key2",
Operation: UpsertBatchOperation,
ItemKey: "key2",
ItemValue: "val2",
},
},
Expand Down
2 changes: 1 addition & 1 deletion fastly/dictionary_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestClient_BatchModifyDictionaryItem_validation(t *testing.T) {
t.Errorf("bad error: %s", err)
}

oversizedDictionaryItems := make([]BatchDictionaryItem, BatchModifyMaximumItems+1)
oversizedDictionaryItems := make([]*BatchDictionaryItem, BatchModifyMaximumItems+1)
err = testClient.BatchModifyDictionaryItems(&BatchModifyDictionaryItemsInput{
Service: "foo",
Dictionary: "bar",
Expand Down
8 changes: 4 additions & 4 deletions fastly/fastly.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
type BatchOperation string

const (
Create BatchOperation = "create"
Update BatchOperation = "update"
Upsert BatchOperation = "upsert"
Delete BatchOperation = "delete"
CreateBatchOperation BatchOperation = "create"
UpdateBatchOperation BatchOperation = "update"
UpsertBatchOperation BatchOperation = "upsert"
DeleteBatchOperation BatchOperation = "delete"

BatchModifyMaximumItems = 1000
)
Expand Down
48 changes: 1 addition & 47 deletions fastly/fixtures/dictionaries/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,4 @@ interactions:
X-Timer:
- S1557352389.584839,VS0,VE185
status: 404 Not Found
code: 404
- request:
body: ""
form: {}
headers:
Fastly-Key:
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent:
- FastlyGo/0.4.3.dev (+github.com/fastly/go-fastly; go1.12)
url: https://api.fastly.com/service/7i6HN3TK9wS159v2gPAZ8A/version/14/dictionary/new_test_dictionary
method: DELETE
response:
body: '{"msg":"Record not found","detail":"Couldn''t find Dictionary ''{ deleted
=\u003e 0000-00-00 00:00:00, name =\u003e new_test_dictionary, service =\u003e
7i6HN3TK9wS159v2gPAZ8A, version =\u003e 14 }''"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-cache
Content-Type:
- application/json
Date:
- Wed, 08 May 2019 21:53:08 GMT
Fastly-Ratelimit-Remaining:
- "992"
Fastly-Ratelimit-Reset:
- "1557352800"
Status:
- 404 Not Found
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-slwdc9036-CONTROL-SLWDC, cache-sjc3647-SJC
X-Timer:
- S1557352389.774751,VS0,VE177
status: 404 Not Found
code: 404
code: 404
1 change: 0 additions & 1 deletion fastly/fixtures/dictionaries/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
1 change: 0 additions & 1 deletion fastly/fixtures/dictionaries/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
1 change: 0 additions & 1 deletion fastly/fixtures/dictionaries/list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
1 change: 0 additions & 1 deletion fastly/fixtures/dictionaries/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
1 change: 0 additions & 1 deletion fastly/fixtures/dictionaries/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
1 change: 0 additions & 1 deletion fastly/fixtures/dictionary_items/cleanup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -46,7 +45,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/create_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -42,7 +41,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -36,7 +35,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/delete_dictionary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -36,7 +35,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/delete_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -36,7 +35,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
2 changes: 0 additions & 2 deletions fastly/fixtures/dictionary_items/dictionary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -44,7 +43,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
4 changes: 0 additions & 4 deletions fastly/fixtures/dictionary_items/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
- bytes
Age:
- "0"
- "0"
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -36,7 +33,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
4 changes: 0 additions & 4 deletions fastly/fixtures/dictionary_items/list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ interactions:
headers:
Accept-Ranges:
- bytes
- bytes
- bytes
Age:
- "0"
- "0"
Cache-Control:
- no-cache
Content-Type:
Expand All @@ -36,7 +33,6 @@ interactions:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
Expand Down
Loading