mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
test: add unit tests for AppStream pass-through feature
This commit is contained in:
committed by
André Roth
parent
29c37293b9
commit
fb7734b5b0
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/aptly-dev/aptly/database"
|
||||
"github.com/aptly-dev/aptly/database/goleveldb"
|
||||
"github.com/aptly-dev/aptly/files"
|
||||
"github.com/aptly-dev/aptly/utils"
|
||||
"github.com/ugorji/go/codec"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
@@ -425,6 +426,41 @@ func (s *PublishedRepoSuite) TestPublish(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
func (s *PublishedRepoSuite) TestPublishAppStream(c *C) {
|
||||
appstreamContent := []byte("DEP-11 test content for Components-amd64.yml.gz")
|
||||
tmpFile := filepath.Join(c.MkDir(), "Components-amd64.yml.gz")
|
||||
c.Assert(os.WriteFile(tmpFile, appstreamContent, 0644), IsNil)
|
||||
|
||||
checksums := utils.ChecksumInfo{Size: int64(len(appstreamContent))}
|
||||
poolPath, err := s.packagePool.Import(tmpFile, "Components-amd64.yml.gz", &checksums, false, s.cs)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
s.snapshot.AppStreamFiles = map[string]string{
|
||||
"main/dep11/Components-amd64.yml.gz": poolPath,
|
||||
}
|
||||
|
||||
err = s.repo.Publish(s.packagePool, s.provider, s.factory, &NullSigner{}, nil, false, "")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
appstreamPath := filepath.Join(s.publishedStorage.PublicPath(), "ppa/dists/squeeze/main/dep11/Components-amd64.yml.gz")
|
||||
c.Check(appstreamPath, PathExists)
|
||||
|
||||
actualContent, err := os.ReadFile(appstreamPath)
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(actualContent, DeepEquals, appstreamContent)
|
||||
|
||||
rf, err := os.Open(filepath.Join(s.publishedStorage.PublicPath(), "ppa/dists/squeeze/Release"))
|
||||
c.Assert(err, IsNil)
|
||||
defer rf.Close()
|
||||
|
||||
cfr := NewControlFileReader(rf, true, false)
|
||||
st, err := cfr.ReadStanza()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
c.Check(st["MD5Sum"], Matches, "(?s).*main/dep11/Components-amd64\\.yml\\.gz.*")
|
||||
c.Check(st["SHA256"], Matches, "(?s).*main/dep11/Components-amd64\\.yml\\.gz.*")
|
||||
}
|
||||
|
||||
func (s *PublishedRepoSuite) TestPublishNoSigner(c *C) {
|
||||
err := s.repo.Publish(s.packagePool, s.provider, s.factory, nil, nil, false, "")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
@@ -135,6 +135,44 @@ func (s *RemoteRepoSuite) TestString(c *C) {
|
||||
s.flat.DownloadSources = true
|
||||
c.Check(s.repo.String(), Equals, "[yandex]: http://mirror.yandex.ru/debian/ squeeze [src] [udeb] [installer]")
|
||||
c.Check(s.flat.String(), Equals, "[exp42]: http://repos.express42.com/virool/precise/ ./ [src]")
|
||||
|
||||
s.repo.DownloadAppStream = true
|
||||
c.Check(s.repo.String(), Equals, "[yandex]: http://mirror.yandex.ru/debian/ squeeze [src] [udeb] [installer] [appstream]")
|
||||
|
||||
s.flat.DownloadAppStream = true
|
||||
c.Check(s.flat.String(), Equals, "[exp42]: http://repos.express42.com/virool/precise/ ./ [src] [appstream]")
|
||||
}
|
||||
|
||||
func (s *RemoteRepoSuite) TestAppStreamPaths(c *C) {
|
||||
s.repo.ReleaseFiles = nil
|
||||
c.Check(s.repo.AppStreamPaths("main"), DeepEquals, []string(nil))
|
||||
|
||||
s.repo.ReleaseFiles = map[string]utils.ChecksumInfo{
|
||||
"main/binary-amd64/Packages": {Size: 100},
|
||||
"main/dep11/Components-amd64.yml.gz": {Size: 200},
|
||||
"main/dep11/Components-i386.yml.gz": {Size: 300},
|
||||
"main/dep11/icons-48x48.tar.gz": {Size: 400},
|
||||
"contrib/dep11/Components-amd64.yml.gz": {Size: 500},
|
||||
"main/source/Sources": {Size: 600},
|
||||
}
|
||||
|
||||
paths := s.repo.AppStreamPaths("main")
|
||||
c.Check(paths, DeepEquals, []string{
|
||||
"main/dep11/Components-amd64.yml.gz",
|
||||
"main/dep11/Components-i386.yml.gz",
|
||||
"main/dep11/icons-48x48.tar.gz",
|
||||
})
|
||||
|
||||
paths = s.repo.AppStreamPaths("contrib")
|
||||
c.Check(paths, DeepEquals, []string{
|
||||
"contrib/dep11/Components-amd64.yml.gz",
|
||||
})
|
||||
|
||||
paths = s.repo.AppStreamPaths("non-free")
|
||||
c.Check(paths, DeepEquals, []string(nil))
|
||||
|
||||
s.repo.ReleaseFiles = map[string]utils.ChecksumInfo{}
|
||||
c.Check(s.repo.AppStreamPaths("main"), DeepEquals, []string(nil))
|
||||
}
|
||||
|
||||
func (s *RemoteRepoSuite) TestNumPackages(c *C) {
|
||||
|
||||
@@ -101,6 +101,62 @@ func (s *SnapshotSuite) TestEncodeDecode(c *C) {
|
||||
c.Assert(snapshot2.packageRefs, IsNil)
|
||||
}
|
||||
|
||||
func (s *SnapshotSuite) TestSnapshotFromRepositoryAppStream(c *C) {
|
||||
s.repo.AppStreamFiles = map[string]string{
|
||||
"main/dep11/Components-amd64.yml.gz": "ab/cd/Components-amd64.yml.gz",
|
||||
"main/dep11/icons-48x48.tar.gz": "ef/gh/icons-48x48.tar.gz",
|
||||
}
|
||||
snapshot, err := NewSnapshotFromRepository("snap-as", s.repo)
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(snapshot.AppStreamFiles, DeepEquals, s.repo.AppStreamFiles)
|
||||
|
||||
s.repo.AppStreamFiles = nil
|
||||
snapshot2, err := NewSnapshotFromRepository("snap-no-as", s.repo)
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(snapshot2.AppStreamFiles, IsNil)
|
||||
}
|
||||
|
||||
func (s *SnapshotSuite) TestSnapshotFromRefListAppStreamMerge(c *C) {
|
||||
snap1, _ := NewSnapshotFromRepository("snap1", s.repo)
|
||||
snap1.AppStreamFiles = map[string]string{
|
||||
"main/dep11/Components-amd64.yml.gz": "aa/bb/Components-amd64.yml.gz",
|
||||
"main/dep11/icons-48x48.tar.gz": "cc/dd/icons-48x48.tar.gz",
|
||||
}
|
||||
|
||||
snap2, _ := NewSnapshotFromRepository("snap2", s.repo)
|
||||
snap2.AppStreamFiles = map[string]string{
|
||||
"contrib/dep11/Components-amd64.yml.gz": "ee/ff/Components-amd64.yml.gz",
|
||||
"main/dep11/Components-amd64.yml.gz": "xx/yy/Components-amd64.yml.gz",
|
||||
}
|
||||
|
||||
merged := NewSnapshotFromRefList("merged", []*Snapshot{snap1, snap2}, s.reflist, "Merged")
|
||||
|
||||
c.Check(len(merged.AppStreamFiles), Equals, 3)
|
||||
c.Check(merged.AppStreamFiles["main/dep11/icons-48x48.tar.gz"], Equals, "cc/dd/icons-48x48.tar.gz")
|
||||
c.Check(merged.AppStreamFiles["contrib/dep11/Components-amd64.yml.gz"], Equals, "ee/ff/Components-amd64.yml.gz")
|
||||
c.Check(merged.AppStreamFiles["main/dep11/Components-amd64.yml.gz"], Equals, "xx/yy/Components-amd64.yml.gz")
|
||||
|
||||
snap3, _ := NewSnapshotFromRepository("snap3", s.repo)
|
||||
snap3.AppStreamFiles = nil
|
||||
snap4, _ := NewSnapshotFromRepository("snap4", s.repo)
|
||||
snap4.AppStreamFiles = nil
|
||||
merged2 := NewSnapshotFromRefList("merged2", []*Snapshot{snap3, snap4}, s.reflist, "Merged2")
|
||||
c.Check(merged2.AppStreamFiles, IsNil)
|
||||
}
|
||||
|
||||
func (s *SnapshotSuite) TestEncodeDecodeAppStream(c *C) {
|
||||
snapshot, _ := NewSnapshotFromRepository("snap-as-enc", s.repo)
|
||||
snapshot.AppStreamFiles = map[string]string{
|
||||
"main/dep11/Components-amd64.yml.gz": "ab/cd/Components-amd64.yml.gz",
|
||||
"main/dep11/icons-48x48.tar.gz": "ef/gh/icons-48x48.tar.gz",
|
||||
}
|
||||
|
||||
decoded := &Snapshot{}
|
||||
c.Assert(decoded.Decode(snapshot.Encode()), IsNil)
|
||||
c.Check(decoded.Name, Equals, snapshot.Name)
|
||||
c.Check(decoded.AppStreamFiles, DeepEquals, snapshot.AppStreamFiles)
|
||||
}
|
||||
|
||||
type SnapshotCollectionSuite struct {
|
||||
PackageListMixinSuite
|
||||
db database.Storage
|
||||
|
||||
Reference in New Issue
Block a user