package httpdl import ( "errors" "net" "strings" "testing" ) // retriesExhausted must wrap (not discard) the underlying cause, so main's // exit-code mapping can still tell a DNS failure from a refused connection. func TestRetriesExhausted(t *testing.T) { cause := &net.DNSError{Err: "no such host", Name: "x.invalid", IsNotFound: true} err := retriesExhausted("http://x", 5, cause) var de *net.DNSError if !errors.As(err, &de) { t.Fatalf("dropped the cause: %v", err) } if !strings.Contains(err.Error(), "after 5 tries") { t.Errorf("missing try count: %v", err) } // A single attempt did not "retry", so it must not claim it did. if one := retriesExhausted("segment 0", 1, cause); strings.Contains(one.Error(), "tries") { t.Errorf("single attempt should not mention tries: %v", one) } }