From c30862dff9f800c018a88cd4514a8de0d8033279 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 11 Feb 2014 21:11:36 +0400 Subject: [PATCH] Build all package refs. --- debian/package.go | 5 +++++ debian/package_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/debian/package.go b/debian/package.go index 1441d763..b9bc1c4a 100644 --- a/debian/package.go +++ b/debian/package.go @@ -345,3 +345,8 @@ func (collection *PackageCollection) ByKey(key []byte) (*Package, error) { func (collection *PackageCollection) Update(p *Package) error { return collection.db.Put(p.Key(), p.Encode()) } + +// AllPackageRefs returns list of all packages as PackageRefList +func (collection *PackageCollection) AllPackageRefs() *PackageRefList { + return &PackageRefList{Refs: collection.db.KeysByPrefix([]byte("P"))} +} diff --git a/debian/package_test.go b/debian/package_test.go index df39931d..7bd14911 100644 --- a/debian/package_test.go +++ b/debian/package_test.go @@ -238,3 +238,12 @@ func (s *PackageCollectionSuite) TestUpdateByKey(c *C) { c.Assert(err, IsNil) c.Assert(p2.Equals(s.p), Equals, true) } + +func (s *PackageCollectionSuite) TestAllPackageRefs(c *C) { + err := s.collection.Update(s.p) + c.Assert(err, IsNil) + + refs := s.collection.AllPackageRefs() + c.Check(refs.Len(), Equals, 1) + c.Check(refs.Refs[0], DeepEquals, s.p.Key()) +}