-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimezones_test.go
More file actions
74 lines (63 loc) · 1.51 KB
/
Copy pathtimezones_test.go
File metadata and controls
74 lines (63 loc) · 1.51 KB
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
package marketstack
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetTimezones(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/timezones" {
t.Errorf("expected path '/timezones', got '%s'", r.URL.Path)
}
response := TimezonesResponse{
Pagination: Pagination{
Limit: 10,
Offset: 0,
Count: 3,
Total: 3,
},
Data: []Timezone{
{
Timezone: "America/New_York",
Abbr: "EST",
AbbrDST: "EDT",
},
{
Timezone: "Europe/London",
Abbr: "GMT",
AbbrDST: "BST",
},
{
Timezone: "Asia/Tokyo",
Abbr: "JST",
AbbrDST: "JST",
},
},
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}))
defer server.Close()
client := NewClient("test-key", nil)
client.SetBaseURL(server.URL)
result, err := client.GetTimezones(context.Background(), &TimezonesOptions{
Limit: 10,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(result.Data) != 3 {
t.Fatalf("expected 3 timezones, got %d", len(result.Data))
}
if result.Data[0].Timezone != "America/New_York" {
t.Errorf("expected timezone 'America/New_York', got '%s'", result.Data[0].Timezone)
}
if result.Data[1].Abbr != "GMT" {
t.Errorf("expected abbr 'GMT', got '%s'", result.Data[1].Abbr)
}
if result.Data[2].AbbrDST != "JST" {
t.Errorf("expected abbr_dst 'JST', got '%s'", result.Data[2].AbbrDST)
}
}