diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go index 9851259790..c0468c9e07 100644 --- a/pkg/domain/infra/tunnel/images.go +++ b/pkg/domain/infra/tunnel/images.go @@ -37,8 +37,8 @@ func (ir *ImageEngine) Remove(ctx context.Context, imagesArg []string, opts enti func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) { filters := make(map[string][]string, len(opts.Filter)) for _, filter := range opts.Filter { - f := strings.Split(filter, "=") - filters[f[0]] = f[1:] + f := strings.SplitN(filter, "=", 2) + filters[f[0]] = append(filters[f[0]], f[1]) } options := new(images.ListOptions).WithAll(opts.All).WithFilters(filters) psImages, err := images.List(ir.ClientCtx, options) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index 9813062645..7bb08fdf0f 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -496,4 +496,53 @@ RUN > file2 }) + It("podman images filter should be AND logic", func() { + dockerfile := `FROM quay.io/libpod/alpine:latest +LABEL abc="" +LABEL xyz="" +` + podmanTest.BuildImage(dockerfile, "test-abc-xyz", "true") + + dockerfile2 := `FROM quay.io/libpod/alpine:latest +LABEL xyz="bar" +` + podmanTest.BuildImage(dockerfile2, "test-xyz", "true") + + session := podmanTest.Podman([]string{"images", "-f", "label=xyz"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(3)) + Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz")) + Expect(session.OutputToString()).To(ContainSubstring("test-xyz")) + + session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(2)) + Expect(session.OutputToString()).To(ContainSubstring("test-xyz")) + + session = podmanTest.Podman([]string{"images", "-f", "label=abc"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(2)) + Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz")) + + session = podmanTest.Podman([]string{"images", "-f", "label=abc", "-f", "label=xyz"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(2)) + Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz")) + + session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar", "-f", "label=abc"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(1)) + + session = podmanTest.Podman([]string{"images", "-f", "label=xyz", "-f", "reference=test-abc-xyz"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(ExitCleanly()) + Expect(session.OutputToStringArray()).To(HaveLen(2)) + Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz")) + }) + })