mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Listing of packages in snapshot.
This commit is contained in:
9
debian/list.go
vendored
9
debian/list.go
vendored
@@ -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
16
debian/list_test.go
vendored
@@ -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
5
debian/snapshot.go
vendored
@@ -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)
|
||||
|
||||
1
debian/snapshot_test.go
vendored
1
debian/snapshot_test.go
vendored
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user