-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathowners_test.go
79 lines (71 loc) · 1.71 KB
/
owners_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package openaq
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
const owners = `{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":1,"name":"OpenAQ admin","locationsCount":7061}]}`
func TestGetOwners(t *testing.T) {
client := NewTestClient(func(req *http.Request) *http.Response {
equals(t, req.URL.String(), "https://api.openaq.org/v3/owners")
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(owners)),
Header: make(http.Header),
}
})
config := &Config{
Client: client,
}
openAQClient, err := NewClient(*config)
if err != nil {
fmt.Println("Failed to create new client")
}
args := &OwnersArgs{}
ctx := context.Background()
body, err := openAQClient.GetOwners(ctx, *args)
expected := OwnersResponse{
Meta: Meta{
Name: "openaq-api",
Website: "/",
Limit: 100,
Page: 1,
Found: float64(1),
},
Results: []Owner{
{
ID: 1,
Name: "OpenAQ admin",
},
},
}
ok(t, err)
fmt.Println(cmp.Diff(&expected, body))
equals(t, &expected, body)
}
func TestGetOwner(t *testing.T) {
client := NewTestClient(func(req *http.Request) *http.Response {
// Test request parameters
equals(t, req.URL.String(), "https://api.openaq.org/v3/owners/1")
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(owners)),
Header: make(http.Header),
}
})
config := &Config{
Client: client,
}
openAQClient, err := NewClient(*config)
if err != nil {
fmt.Println("")
}
ctx := context.Background()
body, err := openAQClient.GetOwner(ctx, 1)
ok(t, err)
equals(t, body.Results[len(body.Results)-1].ID, int64(1))
}