-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrdap-entity_test.go
66 lines (51 loc) · 1.36 KB
/
rdap-entity_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
package adapters
import (
"context"
"errors"
"testing"
"github.com/openrdap/rdap"
"github.com/overmindtech/cli/sdp-go"
"github.com/overmindtech/cli/sdpcache"
)
func TestEntityAdapterSearch(t *testing.T) {
t.Parallel()
realUrls := []string{
"https://rdap.apnic.net/entity/AIC3-AP",
"https://rdap.apnic.net/entity/IRT-APNICRANDNET-AU",
"https://rdap.arin.net/registry/entity/HPINC-Z",
}
src := &RdapEntityAdapter{
ClientFac: func() *rdap.Client { return testRdapClient(t) },
Cache: sdpcache.NewCache(),
}
for _, realUrl := range realUrls {
t.Run(realUrl, func(t *testing.T) {
items, err := src.Search(context.Background(), "global", realUrl, false)
if err != nil {
t.Fatal(err)
}
if len(items) != 1 {
t.Fatalf("Expected 1 item, got %v", len(items))
}
item := items[0]
err = item.Validate()
if err != nil {
t.Error(err)
}
})
}
t.Run("not found", func(t *testing.T) {
_, err := src.Search(context.Background(), "global", "https://rdap.apnic.net/entity/NOTFOUND", false)
if err == nil {
t.Fatal("Expected error")
}
var sdpError *sdp.QueryError
if ok := errors.As(err, &sdpError); ok {
if sdpError.GetErrorType() != sdp.QueryError_NOTFOUND {
t.Errorf("Expected QueryError_NOTFOUND, got %v", sdpError.GetErrorType())
}
} else {
t.Fatalf("Expected QueryError, got %T", err)
}
})
}