mirror of
https://github.com/containers/podman.git
synced 2025-06-13 11:44:19 +08:00
more image binding tests
add two additional bindings tests for image usage. add ability to use search filter on the endpoint. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||||
@ -147,10 +148,36 @@ func SearchImages(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO filters are a bit undefined here in terms of what exactly the input looks
|
|
||||||
// like. We need to understand that a bit more.
|
filter := image.SearchFilter{}
|
||||||
|
if len(query.Filters) > 0 {
|
||||||
|
if len(query.Filters["stars"]) > 0 {
|
||||||
|
stars, err := strconv.Atoi(query.Filters["stars"][0])
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filter.Stars = stars
|
||||||
|
}
|
||||||
|
if len(query.Filters["is-official"]) > 0 {
|
||||||
|
isOfficial, err := strconv.ParseBool(query.Filters["is-official"][0])
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filter.IsOfficial = types.NewOptionalBool(isOfficial)
|
||||||
|
}
|
||||||
|
if len(query.Filters["is-automated"]) > 0 {
|
||||||
|
isAutomated, err := strconv.ParseBool(query.Filters["is-automated"][0])
|
||||||
|
if err != nil {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
filter.IsAutomated = types.NewOptionalBool(isAutomated)
|
||||||
|
}
|
||||||
|
}
|
||||||
options := image.SearchOptions{
|
options := image.SearchOptions{
|
||||||
Filter: image.SearchFilter{},
|
Filter: filter,
|
||||||
Limit: query.Limit,
|
Limit: query.Limit,
|
||||||
}
|
}
|
||||||
results, err := image.SearchImages(query.Term, options)
|
results, err := image.SearchImages(query.Term, options)
|
||||||
|
@ -292,5 +292,58 @@ var _ = Describe("Podman images", func() {
|
|||||||
Expect(data.Comment).To(Equal(testMessage))
|
Expect(data.Comment).To(Equal(testMessage))
|
||||||
|
|
||||||
})
|
})
|
||||||
|
It("History Image", func() {
|
||||||
|
// a bogus name should return a 404
|
||||||
|
_, err := images.History(connText, "foobar")
|
||||||
|
Expect(err).To(Not(BeNil()))
|
||||||
|
code, _ := bindings.CheckResponseCode(err)
|
||||||
|
Expect(code).To(BeNumerically("==", http.StatusNotFound))
|
||||||
|
|
||||||
|
var foundID bool
|
||||||
|
data, err := images.GetImage(connText, alpine.name, nil)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
history, err := images.History(connText, alpine.name)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
for _, i := range history {
|
||||||
|
if i.ID == data.ID {
|
||||||
|
foundID = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expect(foundID).To(BeTrue())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("Search for an image", func() {
|
||||||
|
imgs, err := images.Search(connText, "alpine", nil, nil)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(len(imgs)).To(BeNumerically(">", 1))
|
||||||
|
var foundAlpine bool
|
||||||
|
for _, i := range imgs {
|
||||||
|
if i.Name == "docker.io/library/alpine" {
|
||||||
|
foundAlpine = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expect(foundAlpine).To(BeTrue())
|
||||||
|
|
||||||
|
// Search for alpine with a limit of 10
|
||||||
|
ten := 10
|
||||||
|
imgs, err = images.Search(connText, "docker.io/alpine", &ten, nil)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(len(imgs)).To(BeNumerically("<=", 10))
|
||||||
|
|
||||||
|
// Search for alpine with stars greater than 100
|
||||||
|
filters := make(map[string][]string)
|
||||||
|
filters["stars"] = []string{"100"}
|
||||||
|
imgs, err = images.Search(connText, "docker.io/alpine", nil, filters)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
for _, i := range imgs {
|
||||||
|
Expect(i.Stars).To(BeNumerically(">=", 100))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search with a fqdn
|
||||||
|
imgs, err = images.Search(connText, "quay.io/libpod/alpine_nginx", nil, nil)
|
||||||
|
Expect(len(imgs)).To(BeNumerically(">=", 1))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user