Handle corner-case: null reflist.

This commit is contained in:
Andrey Smirnov
2014-02-24 12:17:24 +04:00
parent 97becf199f
commit 1b64612aef
2 changed files with 9 additions and 0 deletions

5
debian/list.go vendored
View File

@@ -51,6 +51,11 @@ func NewPackageList() *PackageList {
// NewPackageListFromRefList loads packages list from PackageRefList
func NewPackageListFromRefList(reflist *PackageRefList, collection *PackageCollection) (*PackageList, error) {
// empty reflist
if reflist == nil {
return NewPackageList(), nil
}
result := &PackageList{packages: make(map[string]*Package, reflist.Len())}
err := reflist.ForEach(func(key []byte) error {

4
debian/list_test.go vendored
View File

@@ -287,6 +287,10 @@ func (s *PackageListSuite) TestNewPackageListFromRefList(c *C) {
c.Assert(err, IsNil)
c.Check(list.Len(), Equals, 4)
c.Check(list.Add(s.p4), ErrorMatches, "conflict in package.*")
list, err = NewPackageListFromRefList(nil, coll)
c.Assert(err, IsNil)
c.Check(list.Len(), Equals, 0)
}
func (s *PackageListSuite) TestNewPackageRefList(c *C) {