-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters_test.go
80 lines (73 loc) · 2.1 KB
/
parameters_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
80
package openaq
import (
"context"
"fmt"
"io"
"net/http"
"strings"
"testing"
)
const parameters = `{"meta":{"name":"openaq-api","website":"/","page":1,"limit":100,"found":1},"results":[{"id":11,"name":"bc","units":"µg/m³","displayName":"BC","description":"Black Carbon mass concentration","locationsCount":93,"measurementsCount":734}]}`
// func TestGetParameters(t *testing.T) {
// client := NewTestClient(func(req *http.Request) *http.Response {
// equals(t, req.URL.String(), "https://api.openaq.org/v3/parameters")
// return &http.Response{
// StatusCode: 200,
// Body: io.NopCloser(strings.NewReader(parameters)),
// Header: make(http.Header),
// }
// })
// config := &Config{
// Client: client,
// }
// openAQClient, err := NewClient(*config)
// if err != nil {
// fmt.Println("Failed to create new client")
// }
// args := &ParametersArgs{}
// ctx := context.Background()
// body, err := openAQClient.GetParameters(ctx, *args)
// ok(t, err)
// var results []Parameter
// results = append(results, Parameter{
// ID: 11,
// Name: "bc",
// Units: "µg/m³",
// DisplayName: "BC",
// Description: "Black Carbon mass concentration",
// LocationsCount: 93,
// MeasurementsCount: 734,
// })
// equals(t, &ParametersResponse{
// Meta: Meta{
// Name: "openaq-api",
// Website: "/",
// Page: 1,
// Limit: 100,
// Found: 1,
// },
// Results: results,
// }, body)
// }
func TestGetParameter(t *testing.T) {
client := NewTestClient(func(req *http.Request) *http.Response {
// Test request parameters
equals(t, req.URL.String(), "https://api.openaq.org/v3/parameters/11")
return &http.Response{
StatusCode: 200,
Body: io.NopCloser(strings.NewReader(parameters)),
Header: make(http.Header),
}
})
config := &Config{
Client: client,
}
openAQClient, err := NewClient(*config)
if err != nil {
fmt.Println("")
}
ctx := context.Background()
body, err := openAQClient.GetParameter(ctx, 11)
ok(t, err)
equals(t, body.Results[len(body.Results)-1].ID, int64(11))
}