mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-31 04:30:44 +00:00
Find snapshot by source.
This commit is contained in:
Vendored
+12
@@ -207,6 +207,18 @@ func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Sn
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BySnapshotSource looks up snapshots that have specified snapshot as a source
|
||||||
|
func (collection *SnapshotCollection) BySnapshotSource(snapshot *Snapshot) []*Snapshot {
|
||||||
|
result := make([]*Snapshot, 0)
|
||||||
|
|
||||||
|
for _, s := range collection.list {
|
||||||
|
if s.SourceKind == "snapshot" && utils.StrSliceHasItem(s.SourceIDs, snapshot.UUID) {
|
||||||
|
result = append(result, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// ForEach runs method for each snapshot
|
// ForEach runs method for each snapshot
|
||||||
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Vendored
+16
@@ -171,6 +171,22 @@ func (s *SnapshotCollectionSuite) TestFindByRemoteRepoSource(c *C) {
|
|||||||
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot{})
|
c.Check(s.collection.ByRemoteRepoSource(repo3), 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")
|
||||||
|
snapshot5 := NewSnapshotFromRefList("snap5", []*Snapshot{snapshot3}, s.reflist, "desc3")
|
||||||
|
|
||||||
|
c.Assert(s.collection.Add(s.snapshot1), IsNil)
|
||||||
|
c.Assert(s.collection.Add(s.snapshot2), IsNil)
|
||||||
|
c.Assert(s.collection.Add(snapshot3), IsNil)
|
||||||
|
c.Assert(s.collection.Add(snapshot4), IsNil)
|
||||||
|
c.Assert(s.collection.Add(snapshot5), IsNil)
|
||||||
|
|
||||||
|
c.Check(s.collection.BySnapshotSource(s.snapshot1), DeepEquals, []*Snapshot{snapshot3, snapshot4})
|
||||||
|
c.Check(s.collection.BySnapshotSource(s.snapshot2), DeepEquals, []*Snapshot{snapshot3})
|
||||||
|
c.Check(s.collection.BySnapshotSource(snapshot5), DeepEquals, []*Snapshot{})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SnapshotCollectionSuite) TestDrop(c *C) {
|
func (s *SnapshotCollectionSuite) TestDrop(c *C) {
|
||||||
s.collection.Add(s.snapshot1)
|
s.collection.Add(s.snapshot1)
|
||||||
s.collection.Add(s.snapshot2)
|
s.collection.Add(s.snapshot2)
|
||||||
|
|||||||
Reference in New Issue
Block a user