Skip to content

Commit 10d43ba

Browse files
committed
testing: add WHOIS test helper
Add `TestWHOISInfo` helper test allowing to easily manually test WHOIS results. The helper is only run when specifically invoked with `-run`.
1 parent 9a28594 commit 10d43ba

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

hinting/dns_search_domain_fallbacks_test.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package hinting
22

33
import (
44
"crypto/rand"
5+
"fmt"
56
"net"
67
"net/netip"
8+
"os"
9+
"strings"
710
"testing"
811

912
"github.com/stretchr/testify/assert"
@@ -160,13 +163,46 @@ func TestReverseLookupWHOIS(t *testing.T) {
160163
t.Log(tc.name)
161164
for _, v := range tc.values {
162165
t.Log(v.ip)
163-
res := reverseLookupWhois(v.ip)
166+
res := reverseLookupWHOIS(v.ip)
164167
t.Log(res)
165-
assert.Subset(t, res, []string{v.domain}, "")
168+
assert.Subset(t, res, []string{v.domain},
169+
"WHOIS record for IP `%s` does not contain contact information with the domain `%s`.\n"+
170+
"Run `go test -v -run TestWHOISInfo ./hinting/dns_search_domain_fallbacks_test.go -args IP domain`"+
171+
" to debug WHOIS information for `IP` and expected `domain`.",
172+
v.ip, v.domain)
166173
}
167174
}
168175
}
169176

177+
func TestWHOISInfo(t *testing.T) {
178+
if !strings.Contains(fmt.Sprintln(os.Args), "-test.run=") {
179+
return
180+
}
181+
// Manual test for debugging with -run
182+
args := strings.Fields(strings.Split(fmt.Sprintln(os.Args), "-test.run=")[1])
183+
if len(args) == 1 {
184+
// Do not run when not explicitly called with test arguments.
185+
return
186+
}
187+
if len(args) != 3 {
188+
assert.FailNow(t, "Call TestWHOISInfo with"+
189+
"`go test -v -run TestWHOISInfo ./hinting/dns_search_domain_fallbacks_test.go -args IP domain`",
190+
"args: %s", os.Args)
191+
}
192+
arg1 := netip.MustParseAddr(args[1])
193+
arg2 := args[2]
194+
addr := arg1
195+
response, err := resolveWHOISRedirects(addr, ianaWHOIS)
196+
if err != nil {
197+
assert.FailNow(t, "WHOIS lookup failed", "err: %s", err)
198+
}
199+
domains := extractEmailDomains(response)
200+
assert.Subset(t, domains, []string{arg2},
201+
"WHOIS record for IP `%s` does not contain contact information with the domain `%s`.\n"+
202+
"Full WHOIS: %s",
203+
arg1, arg2, response)
204+
}
205+
170206
func TestDomainsFromHostnamesDerivation(t *testing.T) {
171207
testCases := []struct {
172208
name string
@@ -183,13 +219,14 @@ func TestDomainsFromHostnamesDerivation(t *testing.T) {
183219
}{
184220
{hostnames: []string{"82-130-64-0.net4.ethz.ch."}, domains: []string{"net4.ethz.ch", "ethz.ch"}},
185221
{hostnames: []string{"service-id-api-cd-dcz1-server-4-b.ethz.ch."}, domains: []string{"ethz.ch"}},
222+
{hostnames: []string{"cms-publish."}, domains: []string{"local"}},
186223
},
187224
},
188225
{
189-
name: "ETHZ",
226+
name: "KU",
190227
values: []struct {
191228
hostnames []string
192-
domains []string
229+
domains []string
193230
}{
194231
{hostnames: []string{"60.korea.ac.kr.", "sub.korea.ac.kr."}, domains: []string{"korea.ac.kr"}},
195232
},

0 commit comments

Comments
 (0)