Listing of packages in snapshot.

This commit is contained in:
Andrey Smirnov
2013-12-23 14:29:41 +04:00
parent fe61ae1b41
commit 4d950b79ab
5 changed files with 39 additions and 0 deletions

9
debian/list.go vendored
View File

@@ -103,3 +103,12 @@ func (l *PackageRefList) Decode(input []byte) error {
decoder := codec.NewDecoderBytes(input, &codec.MsgpackHandle{})
return decoder.Decode(l)
}
// ForEach calls handler for each package ref in list
//
// TODO: Error handling
func (l *PackageRefList) ForEach(handler func([]byte)) {
for _, p := range l.Refs {
handler(p)
}
}

16
debian/list_test.go vendored
View File

@@ -90,3 +90,19 @@ func (s *PackageListSuite) TestPackageRefListEncodeDecode(c *C) {
c.Check(reflist2.Len(), Equals, reflist.Len())
c.Check(reflist2.Refs, DeepEquals, reflist.Refs)
}
func (s *PackageListSuite) TestPackageRefListForeach(c *C) {
s.list.Add(s.p1)
s.list.Add(s.p3)
s.list.Add(s.p5)
s.list.Add(s.p6)
reflist := NewPackageRefListFromPackageList(s.list)
Len := 0
reflist.ForEach(func([]byte) {
Len++
})
c.Check(Len, Equals, 4)
}

5
debian/snapshot.go vendored
View File

@@ -56,6 +56,11 @@ func (s *Snapshot) NumPackages() int {
return s.packageRefs.Len()
}
// RefList returns list of package refs in snapshot
func (s *Snapshot) RefList() *PackageRefList {
return s.packageRefs
}
// Key is a unique id in DB
func (s *Snapshot) Key() []byte {
return []byte("S" + s.UUID)

View File

@@ -22,6 +22,7 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
c.Check(snapshot.Name, Equals, "snap1")
c.Check(snapshot.NumPackages(), Equals, 3)
c.Check(snapshot.RefList().Len(), Equals, 3)
s.repo.packageRefs = nil
_, err := NewSnapshotFromRepository("snap2", s.repo)