-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipinfo_api_test.go
44 lines (36 loc) · 1.04 KB
/
ipinfo_api_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
package iptrace
import (
"io/ioutil"
"testing"
)
func TestGetAllDataByIP(t *testing.T) {
http := TestCompanyHTTPClient{t: t, fixtureFilename: "fixtures/ipinfo.json", expectedURI: "/ip/192.168.0.1/json", APIKey: "apiKey", BaseURI: defaultBaseURI}
api := IPInfoAPI{HTTP: http}
IPInfo, err := api.GetAllDataByIP("192.168.0.1")
if err != nil {
t.Errorf("Error parsing fixture %s", err)
}
if IPInfo.Country != "Egypt" {
t.Errorf("Name was %s, expected Egypt", IPInfo.Country)
}
}
type TestCompanyHTTPClient struct {
TestHTTPClient
t *testing.T
fixtureFilename string
expectedURI string
APIKey string
BaseURI string
}
func (t TestCompanyHTTPClient) Get(uri string, queryParams interface{}) ([]byte, error) {
if t.expectedURI != uri {
t.t.Errorf("URI was %s, expected %s", uri, t.expectedURI)
}
return ioutil.ReadFile(t.fixtureFilename)
}
func (t TestCompanyHTTPClient) Post(uri string, body interface{}) ([]byte, error) {
if uri != "/companies" {
t.t.Errorf("Wrong endpoint called")
}
return nil, nil
}