package rdns import ( "context" "errors" "net" "testing" "time" ) func TestFCrDNSTransientFailureIsNotCachedForADay(t *testing.T) { r := New() r.lookup = func(context.Context, string) ([]string, error) { return nil, errors.New("i/o timeout") } if r.FCrDNS("66.249.66.1", []string{"googlebot.com"}) { t.Fatal("a timeout is not a confirmation") } var exp time.Time for _, e := range r.fcr { exp = e.exp } if time.Until(exp) > 2*time.Minute { t.Fatalf("a transient failure must be retried soon, expires in %v", time.Until(exp)) } // the name really does not exist: that answer is final r2 := New() r2.lookup = func(context.Context, string) ([]string, error) { return nil, &net.DNSError{Err: "no such host", IsNotFound: true} } r2.FCrDNS("66.249.66.2", []string{"googlebot.com"}) for _, e := range r2.fcr { exp = e.exp } if time.Until(exp) < 23*time.Hour { t.Fatalf("NXDOMAIN keeps the long TTL: %v", time.Until(exp)) } }