If provided isn't a selector, it means we don't have to return a range

Add also more tests about provides
This commit is contained in:
Ettore Di Giacinto 2020-12-16 22:17:13 +01:00
parent 921869d04c
commit ce169f49af
2 changed files with 140 additions and 17 deletions

View File

@ -330,6 +330,9 @@ func (db *InMemoryDatabase) FindPackages(p Package) (Packages, error) {
// Provides: Treat as the replaced package here // Provides: Treat as the replaced package here
if provided, err := db.getProvide(p); err == nil { if provided, err := db.getProvide(p); err == nil {
p = provided p = provided
if !provided.IsSelector() {
return Packages{provided}, nil
}
} }
db.Lock() db.Lock()

View File

@ -98,30 +98,150 @@ var _ = Describe("Database", func() {
}) })
It("Provides replaces definitions", func() { Context("Provides", 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"}}) It("replaces definitions", func() {
Expect(a3.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}})) 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) a3.SetProvides([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}})
Expect(err).ToNot(HaveOccurred()) Expect(a3.GetProvides()).To(Equal([]*DefaultPackage{{Name: "A", Category: "", Version: "1.0"}}))
_, err = db.CreatePackage(a1) _, err := db.CreatePackage(a)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
_, err = db.CreatePackage(a3) _, err = db.CreatePackage(a1)
Expect(err).ToNot(HaveOccurred()) 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))
}) })
}) })
}) })