package spf import ( "fmt" "net" "os" "testing" ) func TestError_Error(t *testing.T) { err := &Error{error: "record returned neutral", errorType: ErrTypeNeutral} if err.Error() != "record returned neutral" { t.Error("Error() should return 'record returned neutral'") } else if err.Type() != ErrTypeNeutral { t.Error("Type() should return ErrTypeNeutral") } } func TestCheckIP(t *testing.T) { includeProviders := true if os.Getenv("SPF_FOSS_PROVIDERS_ONLY") == "1" { fmt.Println("Running tests without non-FOSS providers") includeProviders = false } // Tests for a simple IPv4 address err := CheckIP("209.51.188.0", "gnu.org") if err != nil { t.Error("CheckIP should return nil, got", err) } if includeProviders { // Tests for Google's complex nested IPv4 addresses with redirects and includes err = CheckIP("35.190.247.0", "gmail.com") if err != nil { t.Error("CheckIP should return nil, got", err) } // Tests for mailgun.org's complex nested IPv4 addresses with redirects and includes err = CheckIP("146.20.113.0", "mailgun.org") if err != nil { t.Error("CheckIP should return nil, got", err) } } // Tests for PTR records which yahoo still uses for no good reason err = CheckIP("27.123.204.128", "yahoo.com") if err != nil { t.Error("CheckIP should return nil, got", err) } // Tests for cta.social's A and/or MX records ctaSocialIP, _ := net.LookupIP("cta.social") err = CheckIP(ctaSocialIP[0].String(), "cta.social") if err != nil { t.Error("CheckIP should return nil, got", err) } // Tests for danwin1210.de's simple IPv6 address err = CheckIP("2a01:4f8:c010:d56::1", "danwin1210.de") if err != nil { t.Error("CheckIP should return nil, got", err) } }