-
Notifications
You must be signed in to change notification settings - Fork 0
/
genderize_test.go
76 lines (72 loc) · 1.44 KB
/
genderize_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
package genderize
import (
"testing"
)
func TestIntegration(t *testing.T) {
responses, err := Get([]string{"James", "Eva", "Thunderhorse"})
expectedGenders := map[string]string{
"James": Male,
"Eva": Female,
"Thunderhorse": Unknown,
}
if err != nil {
t.Fatal(err)
}
for _, response := range responses {
expected := expectedGenders[response.Name]
actual := response.Gender
if expected != actual {
t.Errorf("%s: expected %s, got %s",
response.Name, expected, actual)
}
}
}
func TestIntegrationMultiBatch(t *testing.T) {
names := []string{
"Emma",
"Olivia",
"Ava",
"Isabella",
"Sophia",
"Mia",
"Charlotte",
"Amelia",
"Evelyn",
"Abigail",
"Liam",
"Noah",
"William",
"James",
"Logan",
"Benjamin",
"Mason",
"Elijah",
"Oliver",
"Jacob",
}
responses, err := Get(names)
if err != nil {
t.Fatal(err)
}
if len(names) != len(responses) {
t.Fatal("Expected all names to be returned")
}
for i, expected := range names {
actual := responses[i].Name
if expected != actual {
t.Fatal("Expected names to be returned in same order")
}
}
}
func TestInvalidAPIKey(t *testing.T) {
client, err := NewClient(Config{APIKey: "invalid_api_key"})
if err != nil {
t.Fatal(err)
}
_, err = client.Get(Query{Names: []string{"Peter"}})
expectedMsg := "Invalid API key"
if err == nil || err.Error() != expectedMsg {
t.Errorf("Expected error with %v, got %#v",
expectedMsg, err)
}
}