Skip to content

Commit

Permalink
Sync tests for distinfo and homepage with reality
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Dec 22, 2024
1 parent 64b2d26 commit aa1e27b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
39 changes: 31 additions & 8 deletions v23/distinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,32 @@ func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__algorithms_in
"got BLAKE2s, Size, SHA512.")
}

func (s *Suite) Test_distinfoLinesChecker_checkAlgorithmsDistfile__wrong_order_and_SHA512_missing(c *check.C) {
t := s.Init(c)

t.SetUpPackage("category/package")
t.CreateFileLines("category/package/distinfo",
CvsID,
"",
"Size (package-1.0.txt) = 13 bytes",
"BLAKE2s (package-1.0.txt) = ee494623e60caeda840ed7de4fb70db4a36bc92b445b09f12b9ed46094e9bd59")

t.CreateFileLines("distfiles/package-1.0.txt",
"hello, world")
t.FinishSetUp()

G.Check(t.File("category/package"))

// This case doesn't happen in practice, therefore there's no autofix for it.
t.CheckOutputLines(
"ERROR: ~/category/package/distinfo:3: "+
"Expected BLAKE2s, SHA512, Size checksums "+
"for \"package-1.0.txt\", got Size, BLAKE2s.",
"ERROR: ~/category/package/distinfo:3: "+
"Missing SHA512 hash for package-1.0.txt.",
)
}

func (s *Suite) Test_distinfoLinesChecker_checkUnrecordedPatches(c *check.C) {
t := s.Init(c)

Expand Down Expand Up @@ -930,17 +956,14 @@ func (s *Suite) Test_distinfoFileInfo_hasDistfileAlgorithms__code_coverage(c *ch
"SHA512 (dist-a.tar.gz) = 1234",
"Size (dist-a.tar.gz) = 1234",

"SHA1 (dist-b.tar.gz) = 1234",
"other (dist-b.tar.gz) = 1234",
"SHA512 (dist-b.tar.gz) = 1234",
"Size (dist-b.tar.gz) = 1234",

"SHA1 (dist-c.tar.gz) = 1234",
"BLAKE2s (dist-c.tar.gz) = 1234",
"other (dist-c.tar.gz) = 1234",
"Size (dist-c.tar.gz) = 1234",

"SHA1 (dist-d.tar.gz) = 1234",
"BLAKE2s (dist-d.tar.gz) = 1234",
"SHA512 (dist-d.tar.gz) = 1234",
"other (dist-d.tar.gz) = 1234")
Expand All @@ -953,11 +976,11 @@ func (s *Suite) Test_distinfoFileInfo_hasDistfileAlgorithms__code_coverage(c *ch
"ERROR: distinfo:3: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-a.tar.gz\", got other, BLAKE2s, SHA512, Size.",
"ERROR: distinfo:7: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-b.tar.gz\", got SHA1, other, SHA512, Size.",
"ERROR: distinfo:11: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-c.tar.gz\", got SHA1, BLAKE2s, other, Size.",
"ERROR: distinfo:15: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-d.tar.gz\", got SHA1, BLAKE2s, SHA512, other.")
"\"dist-b.tar.gz\", got other, SHA512, Size.",
"ERROR: distinfo:10: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-c.tar.gz\", got BLAKE2s, other, Size.",
"ERROR: distinfo:13: Expected BLAKE2s, SHA512, Size checksums for "+
"\"dist-d.tar.gz\", got BLAKE2s, SHA512, other.")
}

func (s *Suite) Test_computePatchSha1Hex(c *check.C) {
Expand Down
19 changes: 10 additions & 9 deletions v23/homepage.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,27 @@ func (*HomepageChecker) hasAnySuffix(s string, suffixes ...string) bool {
}

func (*HomepageChecker) classifyNetworkError(err error) string {
cause := err
again:
if wrapper, ok := cause.(interface{ Unwrap() error }); ok {
cause = wrapper.Unwrap()
goto again
}

if cause, ok := cause.(*net.DNSError); ok && cause.IsNotFound {
if cause, ok := err.(*net.DNSError); ok && cause.IsNotFound {
return "name not found"
}

if cause, ok := cause.(syscall.Errno); ok {
if cause, ok := err.(syscall.Errno); ok {
if cause == 10061 || cause == syscall.ECONNREFUSED {
return "connection refused"
}
}

if cause, ok := cause.(net.Error); ok && cause.Timeout() {
if cause, ok := err.(net.Error); ok && cause.Timeout() {
return "timeout"
}

if wrapper, ok := err.(interface{ Unwrap() error }); ok {
if cause := wrapper.Unwrap(); cause != nil {
err = wrapper.Unwrap()
goto again
}
}

return sprintf("unknown network error: %s", err)
}
1 change: 1 addition & 0 deletions v23/homepage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,6 @@ func (s *Suite) Test_HomepageChecker_classifyNetworkError(c *check.C) {
test(syscall.ECONNRESET, "unknown network error: connection reset by peer")
test(errors.New("unknown"), "unknown network error: unknown")
test(&net.AddrError{"msg", "addr"}, "unknown network error: address addr: msg")
test(&net.DNSError{Err: "msg", Name: "name", IsNotFound: true}, "name not found")
test(&net.DNSError{Err: "msg", Name: "name"}, "unknown network error: lookup name: msg")
}

0 comments on commit aa1e27b

Please sign in to comment.