forked from openrdap/rdap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
103 lines (81 loc) · 1.96 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// OpenRDAP
// Copyright 2017 Tom Harwood
// MIT License, see the LICENSE file.
package rdap
import (
"fmt"
"testing"
"github.com/openrdap/rdap/test"
)
func verboseFunc() func(text string) {
if testing.Verbose() {
return func(text string) {
fmt.Printf("# %s\n", text)
}
}
return func(text string) {
}
}
func TestClientQueryDomain(t *testing.T) {
test.Start(test.Bootstrap)
test.Start(test.Responses)
defer test.Finish()
client := &Client{
Verbose: verboseFunc(),
}
domain, err := client.QueryDomain("example.cz")
if err != nil {
t.Errorf("Unexpected error: %s", err)
} else if domain == nil {
t.Errorf("Unexpected nil Domain")
} else if domain.LDHName != "example.cz" {
t.Errorf("Unexpected LDHName %s", domain.LDHName)
}
}
func TestClientQueryDomain404(t *testing.T) {
test.Start(test.Bootstrap)
test.Start(test.Responses)
defer test.Finish()
client := &Client{
Verbose: verboseFunc(),
}
_, err := client.QueryDomain("non-existent.cz")
if err == nil {
t.Errorf("Unexpected success")
} else if !isClientError(ObjectDoesNotExist, err) {
t.Errorf("Unexpected err %s", err)
}
}
func TestClientQueryDomainWrongType(t *testing.T) {
test.Start(test.Bootstrap)
test.Start(test.Responses)
defer test.Finish()
client := &Client{
Verbose: verboseFunc(),
}
_, err := client.QueryDomain("wrong-response-type.cz")
if err == nil {
t.Errorf("Unexpected success")
} else if !isClientError(WrongResponseType, err) {
t.Errorf("Unexpected err %s", err)
}
}
func TestClientQueryDomainMalformed(t *testing.T) {
test.Start(test.Bootstrap)
test.Start(test.Responses)
defer test.Finish()
client := &Client{
Verbose: verboseFunc(),
}
_, err := client.QueryDomain("malformed.cz")
if err == nil {
t.Errorf("Unexpected success")
} else if !isClientError(NoWorkingServers, err) {
t.Errorf("Unexpected err %s", err)
}
}
// test Do()
// 1) success, 1 of each query
// 2) bootstrap not supported
// 3) bootstrap no match
// test Help...