-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrencies_test.go
More file actions
74 lines (63 loc) · 1.46 KB
/
Copy pathcurrencies_test.go
File metadata and controls
74 lines (63 loc) · 1.46 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 TestGetCurrencies(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/currencies" {
t.Errorf("expected path '/currencies', got '%s'", r.URL.Path)
}
response := CurrenciesResponse{
Pagination: Pagination{
Limit: 10,
Offset: 0,
Count: 3,
Total: 3,
},
Data: []Currency{
{
Code: "USD",
Symbol: "$",
Name: "US Dollar",
},
{
Code: "EUR",
Symbol: "€",
Name: "Euro",
},
{
Code: "GBP",
Symbol: "£",
Name: "British Pound",
},
},
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response)
}))
defer server.Close()
client := NewClient("test-key", nil)
client.SetBaseURL(server.URL)
result, err := client.GetCurrencies(context.Background(), &CurrenciesOptions{
Limit: 10,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(result.Data) != 3 {
t.Fatalf("expected 3 currencies, got %d", len(result.Data))
}
if result.Data[0].Code != "USD" {
t.Errorf("expected code 'USD', got '%s'", result.Data[0].Code)
}
if result.Data[1].Symbol != "€" {
t.Errorf("expected symbol '€', got '%s'", result.Data[1].Symbol)
}
if result.Data[2].Name != "British Pound" {
t.Errorf("expected name 'British Pound', got '%s'", result.Data[2].Name)
}
}