Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Mar 12, 2024
1 parent 4e646d1 commit 7d2714f
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions ip2locationio/domainwhois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ func TestGetPunycode(t *testing.T) {
}
}

// TestGetBadPunycode calls GetPunycode with space
// to see if it throws error.
func TestGetBadPunycode(t *testing.T) {
config, err := OpenConfiguration("")

if err != nil {
t.Fatalf(`OpenConfiguration(dummy) = %+v, %v, error`, config, err)
}

whois, err := OpenDomainWhois(config)

if err != nil {
t.Fatalf(`OpenDomainWhois(config) = %+v, %v, error`, whois, err)
}

domain := "fake this"
_, err = whois.GetPunycode(domain)

if err == nil {
t.Fatalf(`whois.GetPunycode(domain) = %+v, error`, domain)
}
}

// TestGetNormalText calls GetNormalText
// to see if it returns the correct UTF8 domain.
func TestGetNormalText(t *testing.T) {
Expand All @@ -148,6 +171,29 @@ func TestGetNormalText(t *testing.T) {
}
}

// TestGetBadNormalText calls GetNormalText with space
// to see if it throws error.
func TestGetBadNormalText(t *testing.T) {
config, err := OpenConfiguration("")

if err != nil {
t.Fatalf(`OpenConfiguration(dummy) = %+v, %v, error`, config, err)
}

whois, err := OpenDomainWhois(config)

if err != nil {
t.Fatalf(`OpenDomainWhois(config) = %+v, %v, error`, whois, err)
}

domain := "fake this"
_, err = whois.GetNormalText(domain)

if err == nil {
t.Fatalf(`whois.GetNormalText(domain) = %+v, error`, domain)
}
}

// TestGetDomainName calls GetDomainName
// to see if it returns the correct domain.
func TestGetDomainName(t *testing.T) {
Expand Down Expand Up @@ -187,12 +233,11 @@ func TestGetBadDomainName(t *testing.T) {
t.Fatalf(`OpenDomainWhois(config) = %+v, %v, error`, whois, err)
}

url := "abcde"
// expected := "example.com"
res, err := whois.GetDomainName(url)
url := "fake this"
_, err = whois.GetDomainName(url)

if err == nil {
t.Fatalf(`whois.GetDomainName(url) = %+v, error`, res)
t.Fatalf(`whois.GetDomainName(url) = %+v, error`, url)
}
}

Expand Down

0 comments on commit 7d2714f

Please sign in to comment.