Search snapshots by source repo.

This commit is contained in:
Andrey Smirnov
2014-01-29 16:16:24 +04:00
parent 26267802e9
commit 555256c1fe
2 changed files with 25 additions and 0 deletions

13
debian/snapshot.go vendored
View File

@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"github.com/smira/aptly/database"
"github.com/smira/aptly/utils"
"github.com/ugorji/go/codec"
"log"
"time"
@@ -194,6 +195,18 @@ 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
func (collection *SnapshotCollection) ByRemoteRepoSource(repo *RemoteRepo) []*Snapshot {
result := make([]*Snapshot, 0)
for _, s := range collection.list {
if s.SourceKind == "repo" && utils.StrSliceHasItem(s.SourceIDs, repo.UUID) {
result = append(result, s)
}
}
return result
}
// ForEach runs method for each snapshot
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
var err error

View File

@@ -158,3 +158,15 @@ func (s *SnapshotCollectionSuite) TestForEachAndLen(c *C) {
})
c.Assert(err, Equals, e)
}
func (s *SnapshotCollectionSuite) TestFindByRemoteRepoSource(c *C) {
c.Assert(s.collection.Add(s.snapshot1), IsNil)
c.Assert(s.collection.Add(s.snapshot2), IsNil)
c.Check(s.collection.ByRemoteRepoSource(s.repo1), DeepEquals, []*Snapshot{s.snapshot1})
c.Check(s.collection.ByRemoteRepoSource(s.repo2), DeepEquals, []*Snapshot{s.snapshot2})
repo3, _ := NewRemoteRepo("other", "http://mirror.yandex.ru/debian/", "lenny", []string{"main"}, []string{})
c.Check(s.collection.ByRemoteRepoSource(repo3), DeepEquals, []*Snapshot{})
}