SnapshotCollection.ByLocalRepoSource method.

This commit is contained in:
Andrey Smirnov
2014-02-26 21:30:14 +04:00
parent eff530a284
commit 4df80d38cf
2 changed files with 37 additions and 1 deletions
+13 -1
View File
@@ -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)
+24
View File
@@ -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")