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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
package whois
import (
"strings"
"testing"
"time"
)
func TestClient(t *testing.T) {
scenarios := []struct {
domain string
wantErr bool
}{
{
domain: "example.com",
wantErr: false,
},
{
domain: "name.com",
wantErr: false,
},
{
domain: "name.org",
wantErr: false,
},
{
domain: "name.net",
wantErr: false,
},
{
domain: "name.sh",
wantErr: false,
},
{
domain: "name.io",
wantErr: false,
},
{
domain: "name.red",
wantErr: false,
},
{
domain: "name.green",
wantErr: false,
},
{
domain: "color.black",
wantErr: false,
},
{
domain: "name.cn",
wantErr: false,
},
{
domain: "google.com.br", // name.com.br is handled weirdly by whois.registry.br, so we'll use this instead
wantErr: false,
},
{
domain: "name.ua",
wantErr: false,
},
{
domain: "name.pp.ua",
wantErr: false,
},
{
domain: "name.co.uk",
wantErr: false,
},
{
domain: "name.cz",
wantErr: false,
},
{
domain: "name.me",
wantErr: false,
},
{
domain: "name.im",
wantErr: false,
},
{
domain: "name.uk",
wantErr: false,
},
{
domain: "dot.scot", // name.scot not registered
wantErr: false,
},
{
domain: "name.ru", // expiration date in `paid-till` field
wantErr: false,
},
{
domain: "register.su", // expiration date in `paid-till` field
wantErr: false,
},
{
domain: "nic.mx",
wantErr: false,
},
}
client := NewClient().WithReferralCache(true)
for _, scenario := range scenarios {
t.Run(scenario.domain+"_Query", func(t *testing.T) {
output, err := client.Query(scenario.domain)
if scenario.wantErr && err == nil {
t.Error("expected error, got none")
t.FailNow()
}
if !scenario.wantErr {
if err != nil {
t.Error("expected no error, got", err.Error())
}
if !strings.Contains(strings.ToLower(output), scenario.domain) {
t.Errorf("expected %s in output, got %s", scenario.domain, output)
}
}
})
time.Sleep(50 * time.Millisecond) // Give the WHOIS servers some breathing room
t.Run(scenario.domain+"_QueryAndParse", func(t *testing.T) {
response, err := client.QueryAndParse(scenario.domain)
if scenario.wantErr && err == nil {
t.Error("expected error, got none")
t.FailNow()
}
if !scenario.wantErr {
if err != nil {
t.Error("expected no error, got", err.Error(), "for domain", scenario.domain)
}
if response.ExpirationDate.Unix() <= 0 {
t.Error("expected to have a valid expiry date, got", response.ExpirationDate.Unix(), "for domain", scenario.domain)
}
if len(response.NameServers) == 0 {
t.Errorf("expected to have at least one name server for domain %s", scenario.domain)
}
if len(response.DomainStatuses) == 0 && !strings.HasSuffix(scenario.domain, ".im") && !strings.HasSuffix(scenario.domain, ".mx") && !strings.HasSuffix(scenario.domain, ".cz") {
t.Errorf("expected to have at least one domain status for domain %s", scenario.domain)
}
}
})
time.Sleep(50 * time.Millisecond) // Give the WHOIS servers some breathing room
}
}
|