diff options
Diffstat (limited to 'pkg/bindings/test/volumes_test.go')
-rw-r--r-- | pkg/bindings/test/volumes_test.go | 81 |
1 files changed, 60 insertions, 21 deletions
diff --git a/pkg/bindings/test/volumes_test.go b/pkg/bindings/test/volumes_test.go index dc90d4d00..1f1da3cfa 100644 --- a/pkg/bindings/test/volumes_test.go +++ b/pkg/bindings/test/volumes_test.go @@ -10,6 +10,7 @@ import ( "github.com/containers/podman/v2/pkg/bindings/containers" "github.com/containers/podman/v2/pkg/bindings/volumes" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/containers/podman/v2/pkg/domain/entities/reports" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" @@ -52,7 +53,7 @@ var _ = Describe("Podman volumes", func() { It("create volume", func() { // create a volume with blank config should work - _, err := volumes.Create(connText, entities.VolumeCreateOptions{}) + _, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) vcc := entities.VolumeCreateOptions{ @@ -60,21 +61,21 @@ var _ = Describe("Podman volumes", func() { Label: nil, Options: nil, } - vol, err := volumes.Create(connText, vcc) + vol, err := volumes.Create(connText, vcc, nil) Expect(err).To(BeNil()) Expect(vol.Name).To(Equal("foobar")) // create volume with same name should 500 - _, err = volumes.Create(connText, vcc) + _, err = volumes.Create(connText, vcc, nil) Expect(err).ToNot(BeNil()) code, _ := bindings.CheckResponseCode(err) Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) }) It("inspect volume", func() { - vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}) + vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) - data, err := volumes.Inspect(connText, vol.Name) + data, err := volumes.Inspect(connText, vol.Name, nil) Expect(err).To(BeNil()) Expect(data.Name).To(Equal(vol.Name)) }) @@ -86,13 +87,13 @@ var _ = Describe("Podman volumes", func() { Expect(code).To(BeNumerically("==", http.StatusNotFound)) // Removing an unused volume should work - vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}) + vol, err := volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) err = volumes.Remove(connText, vol.Name, nil) Expect(err).To(BeNil()) // Removing a volume that is being used without force should be 409 - vol, err = volumes.Create(connText, entities.VolumeCreateOptions{}) + vol, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/foobar", vol.Name), "--name", "vtest", alpine.name, "top"}) session.Wait(45) @@ -102,10 +103,10 @@ var _ = Describe("Podman volumes", func() { Expect(code).To(BeNumerically("==", http.StatusConflict)) // Removing with a volume in use with force should work with a stopped container - zero := uint(0) - err = containers.Stop(connText, "vtest", &zero) + err = containers.Stop(connText, "vtest", new(containers.StopOptions).WithTimeout(0)) Expect(err).To(BeNil()) - err = volumes.Remove(connText, vol.Name, bindings.PTrue) + options := new(volumes.RemoveOptions).WithForce(true) + err = volumes.Remove(connText, vol.Name, options) Expect(err).To(BeNil()) }) @@ -118,7 +119,7 @@ var _ = Describe("Podman volumes", func() { // create a bunch of named volumes and make verify with list volNames := []string{"homer", "bart", "lisa", "maggie", "marge"} for i := 0; i < 5; i++ { - _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: volNames[i]}) + _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: volNames[i]}, nil) Expect(err).To(BeNil()) } vols, err = volumes.List(connText, nil) @@ -131,43 +132,81 @@ var _ = Describe("Podman volumes", func() { // list with bad filter should be 500 filters := make(map[string][]string) filters["foobar"] = []string{"1234"} - _, err = volumes.List(connText, filters) + options := new(volumes.ListOptions).WithFilters(filters) + _, err = volumes.List(connText, options) Expect(err).ToNot(BeNil()) code, _ := bindings.CheckResponseCode(err) Expect(code).To(BeNumerically("==", http.StatusInternalServerError)) filters = make(map[string][]string) filters["name"] = []string{"homer"} - vols, err = volumes.List(connText, filters) + options = new(volumes.ListOptions).WithFilters(filters) + vols, err = volumes.List(connText, options) Expect(err).To(BeNil()) Expect(len(vols)).To(BeNumerically("==", 1)) Expect(vols[0].Name).To(Equal("homer")) }) - // TODO we need to add filtering to tests It("prune unused volume", func() { // Pruning when no volumes present should be ok - _, err := volumes.Prune(connText) + _, err := volumes.Prune(connText, nil) Expect(err).To(BeNil()) // Removing an unused volume should work - _, err = volumes.Create(connText, entities.VolumeCreateOptions{}) + _, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) - vols, err := volumes.Prune(connText) + vols, err := volumes.Prune(connText, nil) Expect(err).To(BeNil()) Expect(len(vols)).To(BeNumerically("==", 1)) - _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: "homer"}) + _, err = volumes.Create(connText, entities.VolumeCreateOptions{Name: "homer"}, nil) Expect(err).To(BeNil()) - _, err = volumes.Create(connText, entities.VolumeCreateOptions{}) + _, err = volumes.Create(connText, entities.VolumeCreateOptions{}, nil) Expect(err).To(BeNil()) session := bt.runPodman([]string{"run", "-dt", "-v", fmt.Sprintf("%s:/homer", "homer"), "--name", "vtest", alpine.name, "top"}) session.Wait(45) - vols, err = volumes.Prune(connText) + vols, err = volumes.Prune(connText, nil) + Expect(err).To(BeNil()) + Expect(len(reports.PruneReportsIds(vols))).To(BeNumerically("==", 1)) + _, err = volumes.Inspect(connText, "homer", nil) + Expect(err).To(BeNil()) + + // Removing volume with non matching filter shouldn't prune any volumes + filters := make(map[string][]string) + filters["label"] = []string{"label1=idontmatch"} + _, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ + "label1": "value1", + }}, nil) + Expect(err).To(BeNil()) + options := new(volumes.PruneOptions).WithFilters(filters) + vols, err = volumes.Prune(connText, options) + Expect(err).To(BeNil()) + Expect(len(vols)).To(BeNumerically("==", 0)) + vol2, err := volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ + "label1": "value2", + }}, nil) + Expect(err).To(BeNil()) + _, err = volumes.Create(connText, entities.VolumeCreateOptions{Label: map[string]string{ + "label1": "value3", + }}, nil) + Expect(err).To(BeNil()) + + // Removing volume with matching filter label and value should remove specific entry + filters = make(map[string][]string) + filters["label"] = []string{"label1=value2"} + options = new(volumes.PruneOptions).WithFilters(filters) + vols, err = volumes.Prune(connText, options) Expect(err).To(BeNil()) Expect(len(vols)).To(BeNumerically("==", 1)) - _, err = volumes.Inspect(connText, "homer") + Expect(vols[0].Id).To(Equal(vol2.Name)) + + // Removing volumes with matching filter label should remove all matching volumes + filters = make(map[string][]string) + filters["label"] = []string{"label1"} + options = new(volumes.PruneOptions).WithFilters(filters) + vols, err = volumes.Prune(connText, options) Expect(err).To(BeNil()) + Expect(len(vols)).To(BeNumerically("==", 2)) }) }) |