forked from pieterclaerhout/go-geoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountries_test.go
76 lines (54 loc) · 1.25 KB
/
countries_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 geoip_test
import (
"testing"
"github.com/pieterclaerhout/go-geoip/v2"
"github.com/stretchr/testify/assert"
)
func TestCountryCodeToName(t *testing.T) {
type test struct {
input string
expected string
shouldError bool
}
var tests = []test{
{"BE", "Belgium", false},
{"be", "Belgium", false},
{"XX", "", true},
}
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
actual, err := geoip.CountryCodeToName(tc.input)
if tc.shouldError {
assert.Emptyf(t, actual, tc.input)
assert.Errorf(t, err, tc.input)
} else {
assert.Equalf(t, tc.expected, actual, tc.input)
assert.NoErrorf(t, err, tc.input)
}
})
}
}
func TestCountryNameToCode(t *testing.T) {
type test struct {
input string
expected string
shouldError bool
}
var tests = []test{
{"Belgium", "BE", false},
{"belgium", "BE", false},
{"Non-existing country", "", true},
}
for _, tc := range tests {
t.Run(tc.input, func(t *testing.T) {
actual, err := geoip.CountryNameToCode(tc.input)
if tc.shouldError {
assert.Emptyf(t, actual, tc.input)
assert.Errorf(t, err, tc.input)
} else {
assert.Equalf(t, tc.expected, actual, tc.input)
assert.NoErrorf(t, err, tc.input)
}
})
}
}