feat: add GCS publish backend with config, API, docs, and tests

This commit is contained in:
Pierig Le Saux
2026-03-27 20:18:16 -04:00
committed by André Roth
parent ed4af9a0f6
commit d5fbf0f795
9 changed files with 509 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
package gcs
import (
"testing"
. "gopkg.in/check.v1"
)
// Launch gocheck tests.
func Test(t *testing.T) {
TestingT(t)
}
+75
View File
@@ -0,0 +1,75 @@
package gcs
import (
"path/filepath"
"github.com/aptly-dev/aptly/utils"
. "gopkg.in/check.v1"
)
type PublishedStorageSuite struct{}
var _ = Suite(&PublishedStorageSuite{})
func (s *PublishedStorageSuite) TestString(c *C) {
storage := &PublishedStorage{bucketName: "bucket-1", prefix: "prefix/a"}
c.Check(storage.String(), Equals, "GCS: bucket-1/prefix/a")
}
func (s *PublishedStorageSuite) TestObjectPath(c *C) {
storage := &PublishedStorage{prefix: "root"}
c.Check(storage.objectPath("dists/stable/Release"), Equals, filepath.Join("root", "dists/stable/Release"))
}
func (s *PublishedStorageSuite) TestApplyACLNoOpModes(c *C) {
for _, acl := range []string{"", "none", "private"} {
storage := &PublishedStorage{acl: acl}
err := storage.applyACL(nil)
c.Check(err, IsNil)
}
}
func (s *PublishedStorageSuite) TestApplyACLUnsupported(c *C) {
storage := &PublishedStorage{acl: "bucket-owner-full-control"}
err := storage.applyACL(nil)
c.Assert(err, NotNil)
c.Check(err, ErrorMatches, "unsupported GCS ACL value: bucket-owner-full-control")
}
func (s *PublishedStorageSuite) TestLinkFromPoolMissingMD5(c *C) {
publishedPrefix := "repo"
publishedRelPath := "pool/main/a/aptly"
fileName := "pkg.deb"
relPath := filepath.Join(filepath.Join(publishedPrefix, publishedRelPath), fileName)
storage := &PublishedStorage{pathCache: map[string]string{relPath: "0123456789abcdef0123456789abcdef"}}
err := storage.LinkFromPool(publishedPrefix, publishedRelPath, fileName, nil, "", utils.ChecksumInfo{}, false)
c.Assert(err, NotNil)
c.Check(err, ErrorMatches, "unable to compare object, MD5 checksum missing")
}
func (s *PublishedStorageSuite) TestLinkFromPoolDifferentMD5NoForce(c *C) {
publishedPrefix := "repo"
publishedRelPath := "pool/main/a/aptly"
fileName := "pkg.deb"
relPath := filepath.Join(filepath.Join(publishedPrefix, publishedRelPath), fileName)
storage := &PublishedStorage{pathCache: map[string]string{relPath: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}
err := storage.LinkFromPool(publishedPrefix, publishedRelPath, fileName, nil, "", utils.ChecksumInfo{MD5: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"}, false)
c.Assert(err, NotNil)
c.Check(err, ErrorMatches, ".*file already exists and is different.*")
}
func (s *PublishedStorageSuite) TestLinkFromPoolSameMD5NoUpload(c *C) {
publishedPrefix := "repo"
publishedRelPath := "pool/main/a/aptly"
fileName := "pkg.deb"
relPath := filepath.Join(filepath.Join(publishedPrefix, publishedRelPath), fileName)
storage := &PublishedStorage{pathCache: map[string]string{relPath: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}
err := storage.LinkFromPool(publishedPrefix, publishedRelPath, fileName, nil, "", utils.ChecksumInfo{MD5: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"}, false)
c.Check(err, IsNil)
}