first commit

This commit is contained in:
2026-06-19 12:32:14 +09:00
commit eb8d9b9460
36 changed files with 6502 additions and 0 deletions

28
httpdl/retry_test.go Normal file
View File

@@ -0,0 +1,28 @@
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)
}
}