-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
75 lines (64 loc) · 1.89 KB
/
client_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
package incapsula_api_go
import (
"reflect"
"testing"
)
func Test_it_returns_IPv6_ranges_only(t *testing.T) {
client := Client{}
expected_ranges := []string{
"2a02:e980::/29",
}
ipv6_ranges := client.getIPv6Ranges()
if !reflect.DeepEqual(ipv6_ranges, expected_ranges) {
t.Errorf("Expected '%s' but got '%s'", expected_ranges, ipv6_ranges)
}
}
func Test_it_returns_IPv4_ranges_only(t *testing.T) {
client := Client{}
expected_ranges := []string{
"199.83.128.0/21",
"198.143.32.0/19",
"149.126.72.0/21",
"103.28.248.0/22",
"185.11.124.0/22",
"192.230.64.0/18",
"45.64.64.0/22",
"107.154.0.0/16"}
for _, ip_ranges := range [][]string{client.getIPv4Ranges(), client.getIpRanges()} {
if !reflect.DeepEqual(ip_ranges, expected_ranges) {
t.Errorf("Expected '%s' but got '%s'", expected_ranges, ip_ranges)
}
}
}
func Test_it_returns_the_raw_json_response(t *testing.T) {
client := Client{}
jsonResponse := client.getRawResponse()
expectedResponse := NewResponse().Raw
if jsonResponse != expectedResponse {
t.Errorf("Expected '%s' but got '%s'", expectedResponse, jsonResponse)
}
}
func Test_it_returns_the_res_code_from_the_response(t *testing.T) {
client := Client{}
res := client.getRes()
expectedRes := 0
if res != expectedRes {
t.Errorf("Expected '%v' but got '%v'", expectedRes, res)
}
}
func Test_it_returns_the_res_message_from_the_response(t *testing.T) {
client := Client{}
resMessage := client.getResMessage()
expectedResMessage := "OK"
if resMessage != expectedResMessage {
t.Errorf("Expected '%s' but got '%s'", expectedResMessage, resMessage)
}
}
func Test_it_returns_the_debug_info_from_the_response(t *testing.T) {
client := Client{}
debugInfo := client.getDebugInfo()
expectedDebugInfo := map[string]string{"id-info": "9088"}
if !reflect.DeepEqual(debugInfo, expectedDebugInfo) {
t.Errorf("Expected '%v' but got '%v'", expectedDebugInfo, debugInfo)
}
}