-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain_test.go
84 lines (74 loc) · 2.1 KB
/
domain_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
package checker
import (
"testing"
)
const errorMessage = "some error message"
type expectedCheckDomainResult struct {
registrar Registrar
status Status
}
var (
domainRegistrars = []Registrar{
availableRegistrar{},
unavailableRegistrar{},
ownedRegistrar{},
processingRegistrar{},
errorRegistrar{},
}
registerRegistrarsSuccess = []Registrar{
errorRegistrar{},
unavailableRegistrar{},
ownedRegistrar{},
}
registerRegistrarsFailure = []Registrar{
errorRegistrar{},
unavailableRegistrar{},
}
name = "irrelevant"
)
func TestCheckDomain(t *testing.T) {
t.Run("Test statuses", func(t *testing.T) {
expectLen := len(domainRegistrars) - 1
expectedResults := []expectedCheckDomainResult{
{domainRegistrars[0], Available},
{domainRegistrars[1], Unavailable},
{domainRegistrars[2], Owned},
{domainRegistrars[3], Processing},
}
statuses, _ := CheckDomain(name, domainRegistrars)
if gotLen := len(statuses); gotLen != expectLen {
t.Logf("Expected %d result statuses but received %d", expectLen, gotLen)
t.Fail()
}
// test the results in order of registrar ordering, it should comply
for i, s := range expectedResults {
status := statuses[i]
if status.Status() != s.status {
t.Logf("Expected %T from status but received %T", s.status, status.Status())
t.Fail()
}
if status.Registrar() != s.registrar {
t.Logf("Expected %T from registrar but received %T", s.registrar, status.Registrar())
t.Fail()
}
if status.Domain() != name {
t.Logf("Expected %s from domain but received %s", name, status.Domain())
t.Fail()
}
}
})
}
func TestRegisterDomain(t *testing.T) {
t.Run("Test registering domains with success", func(t *testing.T) {
if s, _ := RegisterDomain(name, registerRegistrarsSuccess); s.Status() != Owned {
t.Logf("Expected %d result, got %d", Owned, s.Status())
t.Fail()
}
})
t.Run("Test registering domains with failure", func(t *testing.T) {
if s, _ := RegisterDomain(name, registerRegistrarsFailure); s.Status() != Unavailable {
t.Logf("Expected %d result, got %d", Unavailable, s.Status())
t.Fail()
}
})
}