-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsypex_test.go
88 lines (79 loc) · 2.09 KB
/
sypex_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
81
82
83
84
85
86
87
88
package sypexgeo
import (
"fmt"
"testing"
)
var geo SxGEO
func init() {
geo = New("examples/SxGeoCity.dat")
}
func TestErrors(t *testing.T) {
fmt.Print("TestErrors... ")
_, err := geo.GetCityFull("0.0.0.0")
if err == nil {
t.Error("Expected error object when used incorrect arguments")
}
fmt.Println("PASS")
}
func TestGetCityFull1(t *testing.T) {
fmt.Print("TestGetCityFull(1)... ")
info, err := geo.GetCityFull("93.73.35.74")
if err != nil {
t.Error(err)
}
if info["city"].(map[string]interface{})["name_en"].(string) != "Kiev" {
t.Error("`name_en` not equal `Kiev`:", info["city"].(map[string]interface{})["name_en"])
}
if info["region"].(map[string]interface{})["name_en"].(string) != "Kyiv" {
t.Error("`name_en` not equal `Kyiv`", info["region"].(map[string]interface{})["name_en"])
}
_, err = geo.GetCityFull("0.0.0.0")
if err == nil {
t.Error("Expected error object when used incorrect arguments")
}
fmt.Println("PASS")
}
func TestGetCityFull2(t *testing.T) {
fmt.Print("TestGetCityFull(2)... ")
info, err := geo.GetCityFull("124.13.35.14")
if err != nil {
t.Error(err)
}
if info["country"].(map[string]interface{})["name_en"].(string) != "Malaysia" {
t.Error("`name_en` not equal `Malaysia`:", info["country"].(map[string]interface{})["name_en"])
}
fmt.Println("PASS")
}
func TestGetCity(t *testing.T) {
fmt.Print("TestGetCity... ")
info, err := geo.GetCity("17.21.34.42")
if err != nil {
t.Error(err)
}
if info["city"].(map[string]interface{})["name_en"].(string) != "Cupertino" {
t.Error("`name_en` not equal `Cupertino`", info["city"].(map[string]interface{})["name_en"])
}
fmt.Println("PASS")
}
func TestGetCountry(t *testing.T) {
fmt.Print("TestGetCountry... ")
code, err := geo.GetCountry("78.120.24.150")
if err != nil {
t.Error(err)
}
if code != "FR" {
t.Error("Country code not equal `FR`", code)
}
fmt.Println("PASS")
}
func TestGetCountryID(t *testing.T) {
fmt.Print("TestGetCountryID... ")
id, err := geo.GetCountryID("111.12.62.12")
if err != nil {
t.Error(err)
}
if id != 48 {
t.Error("Country id not equal 48", id)
}
fmt.Println("PASS")
}