Skip to content

Commit

Permalink
test: add GetN tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Nov 28, 2023
1 parent 63cf7c2 commit c651c8f
Show file tree
Hide file tree
Showing 29 changed files with 671 additions and 154 deletions.
35 changes: 33 additions & 2 deletions fastly/acl_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestClient_ACLEntries(t *testing.T) {
t.Errorf("Bad entries: %v", es)
}

// List with paginator
// List with manual paginator construction
var es2 []*ACLEntry
var paginator *ListPaginator[ACLEntry]
record(t, fixtureBase+"list2", func(c *Client) {
Expand All @@ -92,7 +92,38 @@ func TestClient_ACLEntries(t *testing.T) {
t.Fatal(err)
}
if len(es2) != 1 {
t.Errorf("Bad entries: %v", es)
t.Errorf("Bad entries: %v", es2)
}
if paginator.HasNext() {
t.Errorf("Bad paginator (remaining: %v)", paginator.Remaining())
}

// List with GetN abstraction method for paginator construction
var es3 []*ACLEntry
record(t, fixtureBase+"list3", func(c *Client) {
listACLEntriesInput := &ListACLEntriesInput{
ACLID: testACL.ID,
Direction: "ascend",
PerPage: 50,
ServiceID: testService.ID,
Sort: "ip",
}
paginator = c.GetACLEntries(listACLEntriesInput)

for paginator.HasNext() {
data, err := paginator.GetNext()
if err != nil {
t.Errorf("Bad paginator (remaining: %d): %s", paginator.Remaining(), err)
return
}
es3 = append(es3, data...)
}
})
if err != nil {
t.Fatal(err)
}
if len(es3) != 1 {
t.Errorf("Bad entries: %v", es3)
}
if paginator.HasNext() {
t.Errorf("Bad paginator (remaining: %v)", paginator.Remaining())
Expand Down
33 changes: 31 additions & 2 deletions fastly/dictionary_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestClient_DictionaryItems(t *testing.T) {
t.Errorf("bad dictionary items: %v", dictionaryItems)
}

// List with paginator
// List with manual paginator construction
var dictionaryItems2 []*DictionaryItem
var paginator *ListPaginator[DictionaryItem]
record(t, fixtureBase+"list2", func(c *Client) {
Expand All @@ -86,11 +86,40 @@ func TestClient_DictionaryItems(t *testing.T) {
if err != nil {
t.Fatal(err)
}

if len(dictionaryItems2) != 1 {
t.Errorf("Bad items: %v", dictionaryItems2)
}
if paginator.HasNext() {
t.Errorf("Bad paginator (remaining: %v)", paginator.Remaining())
}

// List with GetN abstraction method for paginator construction
var dictionaryItems3 []*DictionaryItem
record(t, fixtureBase+"list3", func(c *Client) {
listDictionaryItemsInput := &ListDictionaryItemsInput{
DictionaryID: testDictionary.ID,
Direction: "ascend",
PerPage: 50,
ServiceID: testService.ID,
Sort: "item_key",
}
paginator = c.GetDictionaryItems(listDictionaryItemsInput)

for paginator.HasNext() {
data, err := paginator.GetNext()
if err != nil {
t.Errorf("Bad paginator (remaining: %d): %s", paginator.Remaining(), err)
return
}
dictionaryItems3 = append(dictionaryItems3, data...)
}
})
if err != nil {
t.Fatal(err)
}
if len(dictionaryItems3) != 1 {
t.Errorf("Bad items: %v", dictionaryItems3)
}
if paginator.HasNext() {
t.Errorf("Bad paginator (remaining: %v)", paginator.Remaining())
}
Expand Down
14 changes: 7 additions & 7 deletions fastly/fixtures/acl_entries/acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ interactions:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/version/2/acl
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/version/2/acl
method: POST
response:
body: '{"service_id":"IY940xgmfjL6cMyiCs6xL3","version":"2","name":"test_acl_ACLEntries","created_at":"2023-11-28T13:49:41Z","updated_at":"2023-11-28T13:49:41Z","id":"n1qDQsO0hoKxbpZ9igh3O0","deleted_at":null}'
body: '{"service_id":"eDfYsTYU4tLAI0IX2MHsB0","version":"2","name":"test_acl_ACLEntries","updated_at":"2023-11-28T14:44:24Z","deleted_at":null,"created_at":"2023-11-28T14:44:24Z","id":"rpsMUXwZtYZ4IXl7Eekbl3"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -23,11 +23,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:41 GMT
- Tue, 28 Nov 2023 14:44:24 GMT
Fastly-Ratelimit-Remaining:
- "9997"
- "9950"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -43,9 +43,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-4-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-cp-aws-us-east-2-prod-3-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179382.623285,VS0,VE242
- S1701182664.120715,VS0,VE226
status: 200 OK
code: 200
duration: ""
16 changes: 8 additions & 8 deletions fastly/fixtures/acl_entries/create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ interactions:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/acl/n1qDQsO0hoKxbpZ9igh3O0/entry
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/acl/rpsMUXwZtYZ4IXl7Eekbl3/entry
method: POST
response:
body: '{"service_id":"IY940xgmfjL6cMyiCs6xL3","acl_id":"n1qDQsO0hoKxbpZ9igh3O0","ip":"10.0.0.3","negated":0,"subnet":8,"comment":"test
entry","updated_at":"2023-11-28T13:49:42Z","id":"eZ9NhBeIJOg6emvjUX3d67","created_at":"2023-11-28T13:49:42Z"}'
body: '{"service_id":"eDfYsTYU4tLAI0IX2MHsB0","acl_id":"rpsMUXwZtYZ4IXl7Eekbl3","ip":"10.0.0.3","negated":0,"subnet":8,"comment":"test
entry","created_at":"2023-11-28T14:44:24Z","id":"tIri8nZnSi5Eh6d8EipAk0","updated_at":"2023-11-28T14:44:24Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -30,11 +30,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:42 GMT
- Tue, 28 Nov 2023 14:44:24 GMT
Fastly-Ratelimit-Remaining:
- "9996"
- "9949"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -50,9 +50,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179382.893094,VS0,VE232
- S1701182664.373073,VS0,VE212
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/create_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
url: https://api.fastly.com/service
method: POST
response:
body: '{"customer_id":"51MumwLiSJyFTWhtbByYgR","comment":"go-fastly client test","name":"test_service_ACLEntries","type":"vcl","paused":false,"created_at":"2023-11-28T13:49:41Z","versions":[{"testing":false,"comment":"","created_at":"2023-11-28T13:49:41Z","updated_at":"2023-11-28T13:49:41Z","number":1,"deleted_at":null,"deployed":false,"staging":false,"service_id":"IY940xgmfjL6cMyiCs6xL3","active":false,"locked":false}],"id":"IY940xgmfjL6cMyiCs6xL3","updated_at":"2023-11-28T13:49:41Z","publish_key":"","deleted_at":null}'
body: '{"customer_id":"51MumwLiSJyFTWhtbByYgR","comment":"go-fastly client test","name":"test_service_ACLEntries","type":"vcl","created_at":"2023-11-28T14:44:23Z","paused":false,"publish_key":"","id":"eDfYsTYU4tLAI0IX2MHsB0","updated_at":"2023-11-28T14:44:23Z","versions":[{"updated_at":"2023-11-28T14:44:23Z","service_id":"eDfYsTYU4tLAI0IX2MHsB0","active":false,"comment":"","deleted_at":null,"locked":false,"number":1,"testing":false,"deployed":false,"staging":false,"created_at":"2023-11-28T14:44:23Z"}],"deleted_at":null}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -27,11 +27,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:41 GMT
- Tue, 28 Nov 2023 14:44:23 GMT
Fastly-Ratelimit-Remaining:
- "9999"
- "9952"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -47,9 +47,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-3-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-cp-aws-us-east-2-prod-4-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179381.955549,VS0,VE321
- S1701182663.215346,VS0,VE387
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/acl/n1qDQsO0hoKxbpZ9igh3O0/entry/eZ9NhBeIJOg6emvjUX3d67
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/acl/rpsMUXwZtYZ4IXl7Eekbl3/entry/tIri8nZnSi5Eh6d8EipAk0
method: DELETE
response:
body: '{"status":"ok"}'
Expand All @@ -19,11 +19,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:43 GMT
- Tue, 28 Nov 2023 14:44:25 GMT
Fastly-Ratelimit-Remaining:
- "9994"
- "9947"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179383.091559,VS0,VE201
- S1701182666.693225,VS0,VE198
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/delete_acl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/version/2/acl/test_acl_ACLEntries
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/version/2/acl/test_acl_ACLEntries
method: DELETE
response:
body: '{"status":"ok"}'
Expand All @@ -19,11 +19,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:43 GMT
- Tue, 28 Nov 2023 14:44:26 GMT
Fastly-Ratelimit-Remaining:
- "9993"
- "9946"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-cp-aws-us-east-2-prod-4-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179383.313610,VS0,VE256
- S1701182666.915986,VS0,VE276
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/delete_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interactions:
headers:
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0
method: DELETE
response:
body: '{"status":"ok"}'
Expand All @@ -19,11 +19,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:44 GMT
- Tue, 28 Nov 2023 14:44:26 GMT
Fastly-Ratelimit-Remaining:
- "9992"
- "9945"
Fastly-Ratelimit-Reset:
- "1701180000"
- "1701183600"
Pragma:
- no-cache
Status:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-cp-aws-us-east-2-prod-4-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179384.847274,VS0,VE263
- S1701182666.223163,VS0,VE281
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ interactions:
headers:
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/acl/n1qDQsO0hoKxbpZ9igh3O0/entry/eZ9NhBeIJOg6emvjUX3d67
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/acl/rpsMUXwZtYZ4IXl7Eekbl3/entry/tIri8nZnSi5Eh6d8EipAk0
method: GET
response:
body: '{"service_id":"IY940xgmfjL6cMyiCs6xL3","created_at":"2023-11-28T13:49:42Z","negated":"0","subnet":8,"updated_at":"2023-11-28T13:49:42Z","acl_id":"n1qDQsO0hoKxbpZ9igh3O0","ip":"10.0.0.3","id":"eZ9NhBeIJOg6emvjUX3d67","comment":"test
entry"}'
body: '{"acl_id":"rpsMUXwZtYZ4IXl7Eekbl3","service_id":"eDfYsTYU4tLAI0IX2MHsB0","comment":"test
entry","subnet":8,"ip":"10.0.0.3","negated":"0","updated_at":"2023-11-28T14:44:24Z","id":"tIri8nZnSi5Eh6d8EipAk0","created_at":"2023-11-28T14:44:24Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -20,7 +20,7 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:42 GMT
- Tue, 28 Nov 2023 14:44:25 GMT
Pragma:
- no-cache
Status:
Expand All @@ -36,9 +36,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-3-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-cp-aws-us-east-2-prod-4-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179383.546151,VS0,VE169
- S1701182665.218927,VS0,VE198
status: 200 OK
code: 200
duration: ""
12 changes: 6 additions & 6 deletions fastly/fixtures/acl_entries/list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ interactions:
headers:
User-Agent:
- FastlyGo/8.6.4 (+github.com/fastly/go-fastly; go1.19.12)
url: https://api.fastly.com/service/IY940xgmfjL6cMyiCs6xL3/acl/n1qDQsO0hoKxbpZ9igh3O0/entries?direction=descend&page=1&per_page=1&sort=created
url: https://api.fastly.com/service/eDfYsTYU4tLAI0IX2MHsB0/acl/rpsMUXwZtYZ4IXl7Eekbl3/entries?direction=descend&page=1&per_page=1&sort=created
method: GET
response:
body: '[{"id":"eZ9NhBeIJOg6emvjUX3d67","updated_at":"2023-11-28T13:49:42Z","negated":"0","acl_id":"n1qDQsO0hoKxbpZ9igh3O0","subnet":8,"created_at":"2023-11-28T13:49:42Z","service_id":"IY940xgmfjL6cMyiCs6xL3","comment":"test
entry","ip":"10.0.0.3"}]'
body: '[{"acl_id":"rpsMUXwZtYZ4IXl7Eekbl3","service_id":"eDfYsTYU4tLAI0IX2MHsB0","comment":"test
entry","subnet":8,"updated_at":"2023-11-28T14:44:24Z","ip":"10.0.0.3","negated":"0","id":"tIri8nZnSi5Eh6d8EipAk0","created_at":"2023-11-28T14:44:24Z"}]'
headers:
Accept-Ranges:
- bytes
Expand All @@ -20,7 +20,7 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 28 Nov 2023 13:49:42 GMT
- Tue, 28 Nov 2023 14:44:24 GMT
Pragma:
- no-cache
Status:
Expand All @@ -36,9 +36,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-2-prod-3-CONTROL-AWS-UE2, cache-lcy-eglc8600058-LCY
- cache-control-canary-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lcy-eglc8600040-LCY
X-Timer:
- S1701179382.154040,VS0,VE160
- S1701182665.615384,VS0,VE190
status: 200 OK
code: 200
duration: ""
Loading

0 comments on commit c651c8f

Please sign in to comment.