diff --git a/pkg/package/database_mem.go b/pkg/package/database_mem.go index 970d20df..a77406f7 100644 --- a/pkg/package/database_mem.go +++ b/pkg/package/database_mem.go @@ -330,6 +330,9 @@ func (db *InMemoryDatabase) FindPackages(p Package) (Packages, error) { // Provides: Treat as the replaced package here if provided, err := db.getProvide(p); err == nil { p = provided + if !provided.IsSelector() { + return Packages{provided}, nil + } } db.Lock() diff --git a/pkg/package/database_mem_test.go b/pkg/package/database_mem_test.go index c3c13918..b24dd543 100644 --- a/pkg/package/database_mem_test.go +++ b/pkg/package/database_mem_test.go @@ -98,30 +98,150 @@ var _ = Describe("Database", func() { }) - It("Provides replaces definitions", func() { - db := NewInMemoryDatabase(false) - a := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) - a1 := NewPackage("A", "1.1", []*DefaultPackage{}, []*DefaultPackage{}) - a3 := NewPackage("A", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + Context("Provides", func() { - a3.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}}) - Expect(a3.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}})) + It("replaces definitions", func() { + db := NewInMemoryDatabase(false) + a := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + a1 := NewPackage("A", "1.1", []*DefaultPackage{}, []*DefaultPackage{}) + a3 := NewPackage("A", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) - _, err := db.CreatePackage(a) - Expect(err).ToNot(HaveOccurred()) + a3.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}}) + Expect(a3.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}})) - _, err = db.CreatePackage(a1) - Expect(err).ToNot(HaveOccurred()) + _, err := db.CreatePackage(a) + Expect(err).ToNot(HaveOccurred()) - _, err = db.CreatePackage(a3) - Expect(err).ToNot(HaveOccurred()) + _, err = db.CreatePackage(a1) + Expect(err).ToNot(HaveOccurred()) - s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + _, err = db.CreatePackage(a3) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + pack, err := db.FindPackage(s) + Expect(err).ToNot(HaveOccurred()) + Expect(pack).To(Equal(a3)) + }) + + It("replaces definitions", func() { + db := NewInMemoryDatabase(false) + a := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + a1 := NewPackage("A", "1.1", []*DefaultPackage{}, []*DefaultPackage{}) + a3 := NewPackage("A", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + + a3.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}}) + Expect(a3.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}})) + + _, err := db.CreatePackage(a) + Expect(err).ToNot(HaveOccurred()) + + _, err = db.CreatePackage(a1) + Expect(err).ToNot(HaveOccurred()) + + _, err = db.CreatePackage(a3) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + packs, err := db.FindPackages(s) + Expect(err).ToNot(HaveOccurred()) + Expect(packs).To(ContainElement(a3)) + }) + + It("replaces definitions", func() { + db := NewInMemoryDatabase(false) + a := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + a1 := NewPackage("A", "1.1", []*DefaultPackage{}, []*DefaultPackage{}) + z := NewPackage("Z", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + + z.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}}) + Expect(z.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}})) + + _, err := db.CreatePackage(a) + Expect(err).ToNot(HaveOccurred()) + + _, err = db.CreatePackage(a1) + Expect(err).ToNot(HaveOccurred()) + + _, err = db.CreatePackage(z) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + packs, err := db.FindPackages(s) + Expect(err).ToNot(HaveOccurred()) + Expect(packs).To(ContainElement(z)) + }) + + It("replaces definitions of unexisting packages", func() { + db := NewInMemoryDatabase(false) + a1 := NewPackage("A", "1.1", []*DefaultPackage{}, []*DefaultPackage{}) + z := NewPackage("Z", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + + z.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}}) + Expect(z.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}})) + + _, err := db.CreatePackage(a1) + Expect(err).ToNot(HaveOccurred()) + + _, err = db.CreatePackage(z) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + packs, err := db.FindPackages(s) + Expect(err).ToNot(HaveOccurred()) + Expect(packs).To(ContainElement(z)) + }) + + It("replaces definitions of a required package", func() { + db := NewInMemoryDatabase(false) + + c := NewPackage("C", "1.1", []*DefaultPackage{{Name: "A", Category: "", Version: ">=0"}}, []*DefaultPackage{}) + z := NewPackage("Z", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + + z.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}}) + Expect(z.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}})) + + _, err := db.CreatePackage(z) + Expect(err).ToNot(HaveOccurred()) + _, err = db.CreatePackage(c) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", "1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + packs, err := db.FindPackages(s) + Expect(err).ToNot(HaveOccurred()) + Expect(packs).To(ContainElement(z)) + }) + + When("Searching with selectors", func() { + It("replaces definitions of a required package", func() { + db := NewInMemoryDatabase(false) + + c := NewPackage("C", "1.1", []*DefaultPackage{{Name: "A", Category: "", Version: ">=0"}}, []*DefaultPackage{}) + z := NewPackage("Z", "1.3", []*DefaultPackage{}, []*DefaultPackage{}) + + z.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}}) + Expect(z.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: ">=1.0"}})) + + _, err := db.CreatePackage(z) + Expect(err).ToNot(HaveOccurred()) + _, err = db.CreatePackage(c) + Expect(err).ToNot(HaveOccurred()) + + s := NewPackage("A", ">=1.0", []*DefaultPackage{}, []*DefaultPackage{}) + + packs, err := db.FindPackages(s) + Expect(err).ToNot(HaveOccurred()) + Expect(packs).To(ContainElement(z)) + }) + }) - pack, err := db.FindPackage(s) - Expect(err).ToNot(HaveOccurred()) - Expect(pack).To(Equal(a3)) }) + }) })