mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-06 05:30:57 +00:00
SnapshotCollection.ByLocalRepoSource method.
This commit is contained in:
Vendored
+13
-1
@@ -212,7 +212,7 @@ func (collection *SnapshotCollection) ByUUID(uuid string) (*Snapshot, error) {
|
||||
return nil, fmt.Errorf("snapshot with uuid %s not found", uuid)
|
||||
}
|
||||
|
||||
// ByRemoteRepoSource looks up snapshots that have specified RepoteRepo as a source
|
||||
// ByRemoteRepoSource looks up snapshots that have specified RemoteRepo as a source
|
||||
func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
|
||||
@@ -224,6 +224,18 @@ func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Sn
|
||||
return result
|
||||
}
|
||||
|
||||
// ByLocalRepoSource looks up snapshots that have specified LocalRepo as a source
|
||||
func (collection *SnapshotCollection) ByLocalRepoSource(repo *LocalRepo) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
|
||||
for _, s := range collection.list {
|
||||
if s.SourceKind == "local" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
|
||||
result = append(result, s)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// BySnapshotSource looks up snapshots that have specified snapshot as a source
|
||||
func (collection *SnapshotCollection) BySnapshotSource(snapshot *Snapshot) []*Snapshot {
|
||||
result := make([]*Snapshot, 0)
|
||||
|
||||
Vendored
+24
@@ -95,7 +95,9 @@ type SnapshotCollectionSuite struct {
|
||||
PackageListMixinSuite
|
||||
db database.Storage
|
||||
repo1, repo2 *RemoteRepo
|
||||
lrepo1, lrepo2 *LocalRepo
|
||||
snapshot1, snapshot2 *Snapshot
|
||||
snapshot3, snapshot4 *Snapshot
|
||||
collection *SnapshotCollection
|
||||
}
|
||||
|
||||
@@ -113,6 +115,14 @@ func (s *SnapshotCollectionSuite) SetUpTest(c *C) {
|
||||
s.repo2, _ = NewRemoteRepo("android", "http://mirror.yandex.ru/debian/", "lenny", []string{"main"}, []string{}, false)
|
||||
s.repo2.packageRefs = s.reflist
|
||||
s.snapshot2, _ = NewSnapshotFromRepository("snap2", s.repo2)
|
||||
|
||||
s.lrepo1 = NewLocalRepo("local1", "")
|
||||
s.lrepo1.packageRefs = s.reflist
|
||||
s.snapshot3, _ = NewSnapshotFromLocalRepo("snap3", s.lrepo1)
|
||||
|
||||
s.lrepo2 = NewLocalRepo("local2", "")
|
||||
s.lrepo2.packageRefs = s.reflist
|
||||
s.snapshot4, _ = NewSnapshotFromLocalRepo("snap4", s.lrepo2)
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TearDownTest(c *C) {
|
||||
@@ -187,6 +197,20 @@ func (s *SnapshotCollectionSuite) TestFindByRemoteRepoSource(c *C) {
|
||||
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot{})
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TestFindByLocalRepoSource(c *C) {
|
||||
c.Assert(s.collection.Add(s.snapshot1), IsNil)
|
||||
c.Assert(s.collection.Add(s.snapshot2), IsNil)
|
||||
c.Assert(s.collection.Add(s.snapshot3), IsNil)
|
||||
c.Assert(s.collection.Add(s.snapshot4), IsNil)
|
||||
|
||||
c.Check(s.collection.ByLocalRepoSource(s.lrepo1), DeepEquals, []*Snapshot{s.snapshot3})
|
||||
c.Check(s.collection.ByLocalRepoSource(s.lrepo2), DeepEquals, []*Snapshot{s.snapshot4})
|
||||
|
||||
lrepo3 := NewLocalRepo("other", "")
|
||||
|
||||
c.Check(s.collection.ByLocalRepoSource(lrepo3), DeepEquals, []*Snapshot{})
|
||||
}
|
||||
|
||||
func (s *SnapshotCollectionSuite) TestFindSnapshotSource(c *C) {
|
||||
snapshot3 := NewSnapshotFromRefList("snap3", []*Snapshot{s.snapshot1, s.snapshot2}, s.reflist, "desc1")
|
||||
snapshot4 := NewSnapshotFromRefList("snap4", []*Snapshot{s.snapshot1}, s.reflist, "desc2")
|
||||
|
||||
Reference in New Issue
Block a user