From ed180e8e165f76f8cbe949ac960c1074f6c560da Mon Sep 17 00:00:00 2001 From: Martin Simon Date: Mon, 31 Aug 2026 13:21:22 +0200 Subject: [PATCH] Cover ReadLink's non-link and error paths codecov/patch flagged the change at 75% of diff hit. The uncovered lines were the two the existing test could not reach: the fallthrough when no metadata key matches, and the HeadObject error return. Both are worth pinning regardless of the coverage gate. packageIndexByHash calls ReadLink on a path it has only just confirmed exists and treats an error as "leave it alone", so "this is not a link" and "I could not find out" have to stay distinguishable: the first is an empty string with a nil error, the second is an error. ReadLink goes to 100%. --- s3/public_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/s3/public_test.go b/s3/public_test.go index 7f68e01d..ee49852f 100644 --- a/s3/public_test.go +++ b/s3/public_test.go @@ -437,6 +437,24 @@ func (s *PublishedStorageSuite) TestReadLinkMetadataKeyIsCaseInsensitive(c *C) { c.Check(link, Equals, "a/b") } +func (s *PublishedStorageSuite) TestReadLinkOnPlainObject(c *C) { + // An object that is not a link has no SymLink metadata, and ReadLink + // returns an empty string with a nil error rather than failing. + // packageIndexByHash relies on that: it calls ReadLink on a path it has + // only just confirmed exists, and treats an error as "leave it alone". + s.PutFile(c, "a/plain", []byte("test")) + + link, err := s.storage.ReadLink("a/plain") + c.Check(err, IsNil) + c.Check(link, Equals, "") + + // A HeadObject that fails is an error, not an empty link. The two are + // distinguishable so a caller can tell "this is not a link" from "I could + // not find out". + _, err = s.noSuchBucketStorage.ReadLink("a/plain") + c.Check(err, NotNil) +} + func (s *PublishedStorageSuite) TestFileExists(c *C) { s.PutFile(c, "a/b", []byte("test"))