aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings/test
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2020-12-14 08:52:00 -0600
committerbaude <bbaude@redhat.com>2020-12-15 16:04:59 -0600
commit8d4e19634cf73f257ca7f5d2c9506183f6a5b183 (patch)
treeb2687888a89a443a4c85b191d42cd4d1a8049c8c /pkg/bindings/test
parent0fd31e29948631c264df21a128b3de2700f7f007 (diff)
downloadpodman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.tar.gz
podman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.tar.bz2
podman-8d4e19634cf73f257ca7f5d2c9506183f6a5b183.zip
Podman image bindings for 3.0
Begin the migration of the image bindings for podman 3.0. this includes the use of options for each binding. build was intentionally not converted as I believe it needs more discussion before migration. specifically, the build options themselves. also noteworthly is that the remove image and remove images bindings were merged into one. the remove images (or batch remove) has one downside in that the errors return no longer adhere to http return codes. this should be discussed and reimplemented in subsequent code. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/test')
-rw-r--r--pkg/bindings/test/auth_test.go42
-rw-r--r--pkg/bindings/test/images_test.go100
-rw-r--r--pkg/bindings/test/info_test.go4
-rw-r--r--pkg/bindings/test/manifests_test.go4
4 files changed, 67 insertions, 83 deletions
diff --git a/pkg/bindings/test/auth_test.go b/pkg/bindings/test/auth_test.go
index 4565b82b0..e647b3c36 100644
--- a/pkg/bindings/test/auth_test.go
+++ b/pkg/bindings/test/auth_test.go
@@ -9,7 +9,6 @@ import (
"github.com/containers/image/v5/types"
podmanRegistry "github.com/containers/podman/v2/hack/podman-registry-go"
"github.com/containers/podman/v2/pkg/bindings/images"
- "github.com/containers/podman/v2/pkg/domain/entities"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
@@ -52,27 +51,19 @@ var _ = Describe("Podman images", func() {
imageRef := imageRep + ":" + imageTag
// Tag the alpine image and verify it has worked.
- err = images.Tag(bt.conn, alpine.shortName, imageTag, imageRep)
+ err = images.Tag(bt.conn, alpine.shortName, imageTag, imageRep, nil)
Expect(err).To(BeNil())
_, err = images.GetImage(bt.conn, imageRef, nil)
Expect(err).To(BeNil())
// Now push the image.
- pushOpts := entities.ImagePushOptions{
- Username: registry.User,
- Password: registry.Password,
- SkipTLSVerify: types.OptionalBoolTrue,
- }
- err = images.Push(bt.conn, imageRef, imageRef, pushOpts)
+ pushOpts := new(images.PushOptions)
+ err = images.Push(bt.conn, imageRef, imageRef, pushOpts.WithUsername(registry.User).WithPassword(registry.Password).WithSkipTLSVerify(true))
Expect(err).To(BeNil())
// Now pull the image.
- pullOpts := entities.ImagePullOptions{
- Username: registry.User,
- Password: registry.Password,
- SkipTLSVerify: types.OptionalBoolTrue,
- }
- _, err = images.Pull(bt.conn, imageRef, pullOpts)
+ pullOpts := new(images.PullOptions)
+ _, err = images.Pull(bt.conn, imageRef, pullOpts.WithSkipTLSVerify(true).WithPassword(registry.Password).WithUsername(registry.User))
Expect(err).To(BeNil())
})
@@ -110,33 +101,24 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil())
// Tag the alpine image and verify it has worked.
- err = images.Tag(bt.conn, alpine.shortName, imageTag, imageRep)
+ err = images.Tag(bt.conn, alpine.shortName, imageTag, imageRep, nil)
Expect(err).To(BeNil())
_, err = images.GetImage(bt.conn, imageRef, nil)
Expect(err).To(BeNil())
// Now push the image.
- pushOpts := entities.ImagePushOptions{
- Authfile: authFilePath,
- SkipTLSVerify: types.OptionalBoolTrue,
- }
- err = images.Push(bt.conn, imageRef, imageRef, pushOpts)
+ pushOpts := new(images.PushOptions)
+ err = images.Push(bt.conn, imageRef, imageRef, pushOpts.WithAuthfile(authFilePath).WithSkipTLSVerify(true))
Expect(err).To(BeNil())
// Now pull the image.
- pullOpts := entities.ImagePullOptions{
- Authfile: authFilePath,
- SkipTLSVerify: types.OptionalBoolTrue,
- }
- _, err = images.Pull(bt.conn, imageRef, pullOpts)
+ pullOpts := new(images.PullOptions)
+ _, err = images.Pull(bt.conn, imageRef, pullOpts.WithAuthfile(authFilePath).WithSkipTLSVerify(true))
Expect(err).To(BeNil())
// Last, but not least, exercise search.
- searchOptions := entities.ImageSearchOptions{
- Authfile: authFilePath,
- SkipTLSVerify: types.OptionalBoolTrue,
- }
- _, err = images.Search(bt.conn, imageRef, searchOptions)
+ searchOptions := new(images.SearchOptions)
+ _, err = images.Search(bt.conn, imageRef, searchOptions.WithSkipTLSVerify(true).WithAuthfile(authFilePath))
Expect(err).To(BeNil())
})
diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go
index 684f110e8..b6362a631 100644
--- a/pkg/bindings/test/images_test.go
+++ b/pkg/bindings/test/images_test.go
@@ -9,7 +9,6 @@ import (
"github.com/containers/podman/v2/pkg/bindings"
"github.com/containers/podman/v2/pkg/bindings/containers"
"github.com/containers/podman/v2/pkg/bindings/images"
- "github.com/containers/podman/v2/pkg/domain/entities"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
@@ -75,8 +74,9 @@ var _ = Describe("Podman images", func() {
// of bool or not. What should we do ?
// Expect(data.Size).To(BeZero())
+ options := new(images.GetOptions).WithSize(true)
// Enabling the size parameter should result in size being populated
- data, err = images.GetImage(bt.conn, alpine.name, bindings.PTrue)
+ data, err = images.GetImage(bt.conn, alpine.name, options)
Expect(err).To(BeNil())
Expect(data.Size).To(BeNumerically(">", 0))
})
@@ -84,23 +84,19 @@ var _ = Describe("Podman images", func() {
// Test to validate the remove image api
It("remove image", func() {
// Remove invalid image should be a 404
- response, err := images.Remove(bt.conn, "foobar5000", nil)
- Expect(err).ToNot(BeNil())
- Expect(response).To(BeNil())
- code, _ := bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusNotFound))
+ response, errs := images.Remove(bt.conn, []string{"foobar5000"}, nil)
+ Expect(len(errs)).To(BeNumerically(">", 0))
+ code, _ := bindings.CheckResponseCode(errs[0])
// Remove an image by name, validate image is removed and error is nil
inspectData, err := images.GetImage(bt.conn, busybox.shortName, nil)
Expect(err).To(BeNil())
- response, err = images.Remove(bt.conn, busybox.shortName, nil)
- Expect(err).To(BeNil())
- code, _ = bindings.CheckResponseCode(err)
+ response, errs = images.Remove(bt.conn, []string{busybox.shortName}, nil)
+ Expect(len(errs)).To(BeZero())
Expect(inspectData.ID).To(Equal(response.Deleted[0]))
inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil)
code, _ = bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Start a container with alpine image
var top string = "top"
@@ -113,24 +109,21 @@ var _ = Describe("Podman images", func() {
// try to remove the image "alpine". This should fail since we are not force
// deleting hence image cannot be deleted until the container is deleted.
- response, err = images.Remove(bt.conn, alpine.shortName, nil)
- code, _ = bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusConflict))
+ response, errs = images.Remove(bt.conn, []string{alpine.shortName}, nil)
+ code, _ = bindings.CheckResponseCode(errs[0])
// Removing the image "alpine" where force = true
- options := images.RemoveOptions{}
- response, err = images.Remove(bt.conn, alpine.shortName, options.WithForce(true))
- Expect(err).To(BeNil())
+ options := new(images.RemoveOptions).WithForce(true)
+ response, errs = images.Remove(bt.conn, []string{alpine.shortName}, options)
+ Expect(len(errs)).To(BeZero())
// To be extra sure, check if the previously created container
// is gone as well.
_, err = containers.Inspect(bt.conn, "top", bindings.PFalse)
code, _ = bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Now make sure both images are gone.
inspectData, err = images.GetImage(bt.conn, busybox.shortName, nil)
code, _ = bindings.CheckResponseCode(err)
- Expect(code).To(BeNumerically("==", http.StatusNotFound))
inspectData, err = images.GetImage(bt.conn, alpine.shortName, nil)
code, _ = bindings.CheckResponseCode(err)
@@ -139,14 +132,15 @@ var _ = Describe("Podman images", func() {
// Tests to validate the image tag command.
It("tag image", func() {
+
// Validates if invalid image name is given a bad response is encountered.
- err = images.Tag(bt.conn, "dummy", "demo", alpine.shortName)
+ err = images.Tag(bt.conn, "dummy", "demo", alpine.shortName, nil)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Validates if the image is tagged successfully.
- err = images.Tag(bt.conn, alpine.shortName, "demo", alpine.shortName)
+ err = images.Tag(bt.conn, alpine.shortName, "demo", alpine.shortName, nil)
Expect(err).To(BeNil())
// Validates if name updates when the image is retagged.
@@ -158,7 +152,7 @@ var _ = Describe("Podman images", func() {
// Test to validate the List images command.
It("List image", func() {
// Array to hold the list of images returned
- imageSummary, err := images.List(bt.conn, nil, nil)
+ imageSummary, err := images.List(bt.conn, nil)
// There Should be no errors in the response.
Expect(err).To(BeNil())
// Since in the begin context two images are created the
@@ -168,7 +162,7 @@ var _ = Describe("Podman images", func() {
// Adding one more image. There Should be no errors in the response.
// And the count should be three now.
bt.Pull("testimage:20200929")
- imageSummary, err = images.List(bt.conn, nil, nil)
+ imageSummary, err = images.List(bt.conn, nil)
Expect(err).To(BeNil())
Expect(len(imageSummary)).To(Equal(3))
@@ -183,13 +177,15 @@ var _ = Describe("Podman images", func() {
// List images with a filter
filters := make(map[string][]string)
filters["reference"] = []string{alpine.name}
- filteredImages, err := images.List(bt.conn, bindings.PFalse, filters)
+ options := new(images.ListOptions).WithFilters(filters).WithAll(false)
+ filteredImages, err := images.List(bt.conn, options)
Expect(err).To(BeNil())
Expect(len(filteredImages)).To(BeNumerically("==", 1))
// List images with a bad filter
filters["name"] = []string{alpine.name}
- _, err = images.List(bt.conn, bindings.PFalse, filters)
+ options = new(images.ListOptions).WithFilters(filters)
+ _, err = images.List(bt.conn, options)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -214,8 +210,8 @@ var _ = Describe("Podman images", func() {
It("Load|Import Image", func() {
// load an image
- _, err := images.Remove(bt.conn, alpine.name, nil)
- Expect(err).To(BeNil())
+ _, errs := images.Remove(bt.conn, []string{alpine.name}, nil)
+ Expect(len(errs)).To(BeZero())
exists, err := images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
Expect(exists).To(BeFalse())
@@ -232,13 +228,14 @@ var _ = Describe("Podman images", func() {
// load with a repo name
f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
Expect(err).To(BeNil())
- _, err = images.Remove(bt.conn, alpine.name, nil)
- Expect(err).To(BeNil())
+ _, errs = images.Remove(bt.conn, []string{alpine.name}, nil)
+ Expect(len(errs)).To(BeZero())
exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
Expect(exists).To(BeFalse())
newName := "quay.io/newname:fizzle"
- names, err = images.Load(bt.conn, f, &newName)
+ options := new(images.LoadOptions).WithReference(newName)
+ names, err = images.Load(bt.conn, f, options)
Expect(err).To(BeNil())
Expect(names.Names[0]).To(Equal(alpine.name))
exists, err = images.Exists(bt.conn, newName)
@@ -248,13 +245,13 @@ var _ = Describe("Podman images", func() {
// load with a bad repo name should trigger a 500
f, err = os.Open(filepath.Join(ImageCacheDir, alpine.tarballName))
Expect(err).To(BeNil())
- _, err = images.Remove(bt.conn, alpine.name, nil)
- Expect(err).To(BeNil())
+ _, errs = images.Remove(bt.conn, []string{alpine.name}, nil)
+ Expect(len(errs)).To(BeZero())
exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
Expect(exists).To(BeFalse())
- badName := "quay.io/newName:fizzle"
- _, err = images.Load(bt.conn, f, &badName)
+ options = new(images.LoadOptions).WithReference("quay.io/newName:fizzle")
+ _, err = images.Load(bt.conn, f, options)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -266,7 +263,7 @@ var _ = Describe("Podman images", func() {
w, err := os.Create(filepath.Join(bt.tempDirPath, alpine.tarballName))
defer w.Close()
Expect(err).To(BeNil())
- err = images.Export(bt.conn, alpine.name, w, nil, nil)
+ err = images.Export(bt.conn, []string{alpine.name}, w, nil)
Expect(err).To(BeNil())
_, err = os.Stat(exportPath)
Expect(err).To(BeNil())
@@ -276,8 +273,8 @@ var _ = Describe("Podman images", func() {
It("Import Image", func() {
// load an image
- _, err = images.Remove(bt.conn, alpine.name, nil)
- Expect(err).To(BeNil())
+ _, errs := images.Remove(bt.conn, []string{alpine.name}, nil)
+ Expect(len(errs)).To(BeZero())
exists, err := images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
Expect(exists).To(BeFalse())
@@ -286,7 +283,8 @@ var _ = Describe("Podman images", func() {
Expect(err).To(BeNil())
changes := []string{"CMD /bin/foobar"}
testMessage := "test_import"
- _, err = images.Import(bt.conn, changes, &testMessage, &alpine.name, nil, f)
+ options := new(images.ImportOptions).WithMessage(testMessage).WithChanges(changes).WithReference(alpine.name)
+ _, err = images.Import(bt.conn, f, options)
Expect(err).To(BeNil())
exists, err = images.Exists(bt.conn, alpine.name)
Expect(err).To(BeNil())
@@ -299,7 +297,7 @@ var _ = Describe("Podman images", func() {
It("History Image", func() {
// a bogus name should return a 404
- _, err := images.History(bt.conn, "foobar")
+ _, err := images.History(bt.conn, "foobar", nil)
Expect(err).To(Not(BeNil()))
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusNotFound))
@@ -307,7 +305,7 @@ var _ = Describe("Podman images", func() {
var foundID bool
data, err := images.GetImage(bt.conn, alpine.name, nil)
Expect(err).To(BeNil())
- history, err := images.History(bt.conn, alpine.name)
+ history, err := images.History(bt.conn, alpine.name, nil)
Expect(err).To(BeNil())
for _, i := range history {
if i.ID == data.ID {
@@ -319,7 +317,7 @@ var _ = Describe("Podman images", func() {
})
It("Search for an image", func() {
- reports, err := images.Search(bt.conn, "alpine", entities.ImageSearchOptions{})
+ reports, err := images.Search(bt.conn, "alpine", nil)
Expect(err).To(BeNil())
Expect(len(reports)).To(BeNumerically(">", 1))
var foundAlpine bool
@@ -332,25 +330,29 @@ var _ = Describe("Podman images", func() {
Expect(foundAlpine).To(BeTrue())
// Search for alpine with a limit of 10
- reports, err = images.Search(bt.conn, "docker.io/alpine", entities.ImageSearchOptions{Limit: 10})
+ options := new(images.SearchOptions).WithLimit(10)
+ reports, err = images.Search(bt.conn, "docker.io/alpine", options)
Expect(err).To(BeNil())
Expect(len(reports)).To(BeNumerically("<=", 10))
+ filters := make(map[string][]string)
+ filters["stars"] = []string{"100"}
// Search for alpine with stars greater than 100
- reports, err = images.Search(bt.conn, "docker.io/alpine", entities.ImageSearchOptions{Filters: []string{"stars=100"}})
+ options = new(images.SearchOptions).WithFilters(filters)
+ reports, err = images.Search(bt.conn, "docker.io/alpine", options)
Expect(err).To(BeNil())
for _, i := range reports {
Expect(i.Stars).To(BeNumerically(">=", 100))
}
// Search with a fqdn
- reports, err = images.Search(bt.conn, "quay.io/libpod/alpine_nginx", entities.ImageSearchOptions{})
+ reports, err = images.Search(bt.conn, "quay.io/libpod/alpine_nginx", nil)
Expect(len(reports)).To(BeNumerically(">=", 1))
})
It("Prune images", func() {
- trueBoxed := true
- results, err := images.Prune(bt.conn, &trueBoxed, nil)
+ options := new(images.PruneOptions).WithAll(true)
+ results, err := images.Prune(bt.conn, options)
Expect(err).NotTo(HaveOccurred())
Expect(len(results)).To(BeNumerically(">", 0))
Expect(results).To(ContainElement("docker.io/library/alpine:latest"))
@@ -360,7 +362,7 @@ var _ = Describe("Podman images", func() {
It("Image Pull", func() {
rawImage := "docker.io/library/busybox:latest"
- pulledImages, err := images.Pull(bt.conn, rawImage, entities.ImagePullOptions{})
+ pulledImages, err := images.Pull(bt.conn, rawImage, nil)
Expect(err).NotTo(HaveOccurred())
Expect(len(pulledImages)).To(Equal(1))
@@ -369,11 +371,11 @@ var _ = Describe("Podman images", func() {
Expect(exists).To(BeTrue())
// Make sure the normalization AND the full-transport reference works.
- _, err = images.Pull(bt.conn, "docker://"+rawImage, entities.ImagePullOptions{})
+ _, err = images.Pull(bt.conn, "docker://"+rawImage, nil)
Expect(err).NotTo(HaveOccurred())
// The v2 endpoint only supports the docker transport. Let's see if that's really true.
- _, err = images.Pull(bt.conn, "bogus-transport:bogus.com/image:reference", entities.ImagePullOptions{})
+ _, err = images.Pull(bt.conn, "bogus-transport:bogus.com/image:reference", nil)
Expect(err).To(HaveOccurred())
})
})
diff --git a/pkg/bindings/test/info_test.go b/pkg/bindings/test/info_test.go
index 6cd5d6724..735de25b8 100644
--- a/pkg/bindings/test/info_test.go
+++ b/pkg/bindings/test/info_test.go
@@ -17,7 +17,6 @@ var _ = Describe("Podman info", func() {
var (
bt *bindingTest
s *gexec.Session
- t bool = true
)
BeforeEach(func() {
@@ -39,7 +38,8 @@ var _ = Describe("Podman info", func() {
Expect(err).To(BeNil())
Expect(info.Host.Arch).To(Equal(runtime.GOARCH))
Expect(info.Host.OS).To(Equal(runtime.GOOS))
- i, err := images.List(bt.conn, &t, nil)
+ listOptions := new(images.ListOptions)
+ i, err := images.List(bt.conn, listOptions.WithAll(true))
Expect(err).To(BeNil())
Expect(info.Store.ImageStore.Number).To(Equal(len(i)))
})
diff --git a/pkg/bindings/test/manifests_test.go b/pkg/bindings/test/manifests_test.go
index a4ecaa20f..421004b8c 100644
--- a/pkg/bindings/test/manifests_test.go
+++ b/pkg/bindings/test/manifests_test.go
@@ -47,8 +47,8 @@ var _ = Describe("Podman containers ", func() {
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
- _, err = images.Remove(bt.conn, id, nil)
- Expect(err).To(BeNil())
+ _, errs := images.Remove(bt.conn, []string{id}, nil)
+ Expect(len(errs)).To(BeZero())
// create manifest list with images
id, err = manifests.Create(bt.conn, []string{"quay.io/libpod/foobar:latest"}, []string{alpine.name}, nil)