summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/images/history.go20
-rw-r--r--cmd/podman/images/list.go72
-rw-r--r--cmd/podman/images/rm.go5
-rw-r--r--cmd/podman/root.go4
-rw-r--r--pkg/domain/entities/images.go1
-rw-r--r--pkg/domain/infra/abi/images.go4
-rw-r--r--pkg/domain/infra/abi/images_list.go9
-rw-r--r--test/e2e/common_test.go14
-rw-r--r--test/e2e/images_test.go98
-rw-r--r--test/e2e/rmi_test.go7
-rw-r--r--test/utils/utils.go2
11 files changed, 139 insertions, 97 deletions
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index b8d216cc1..ce153aa46 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -89,22 +89,20 @@ func history(cmd *cobra.Command, args []string) error {
hdr := "ID\tCREATED\tCREATED BY\tSIZE\tCOMMENT\n"
row := "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- if len(opts.format) > 0 {
+ switch {
+ case len(opts.format) > 0:
hdr = ""
row = opts.format
if !strings.HasSuffix(opts.format, "\n") {
row += "\n"
}
- } else {
- switch {
- case opts.human:
- row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- case opts.noTrunc:
- row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- case opts.quiet:
- hdr = ""
- row = "{{.ID}}\n"
- }
+ case opts.quiet:
+ hdr = ""
+ row = "{{.ID}}\n"
+ case opts.human:
+ row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
+ case opts.noTrunc:
+ row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
}
format := hdr + "{{range . }}" + row + "{{end}}"
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 552fed804..83c039ed3 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -99,14 +99,29 @@ func images(cmd *cobra.Command, args []string) error {
return err
}
- imageS := summaries
- sort.Slice(imageS, sortFunc(listFlag.sort, imageS))
+ switch {
+ case listFlag.quiet:
+ return writeId(summaries)
+ case cmd.Flag("format").Changed && listFlag.format == "json":
+ return writeJSON(summaries)
+ default:
+ return writeTemplate(summaries)
+ }
+}
- if cmd.Flag("format").Changed && listFlag.format == "json" {
- return writeJSON(imageS)
- } else {
- return writeTemplate(imageS, err)
+func writeId(imageS []*entities.ImageSummary) error {
+ var ids = map[string]struct{}{}
+ for _, e := range imageS {
+ i := "sha256:" + e.ID
+ if !listFlag.noTrunc {
+ i = fmt.Sprintf("%12.12s", e.ID)
+ }
+ ids[i] = struct{}{}
}
+ for k := range ids {
+ fmt.Fprint(os.Stdout, k+"\n")
+ }
+ return nil
}
func writeJSON(imageS []*entities.ImageSummary) error {
@@ -131,7 +146,7 @@ func writeJSON(imageS []*entities.ImageSummary) error {
return enc.Encode(imgs)
}
-func writeTemplate(imageS []*entities.ImageSummary, err error) error {
+func writeTemplate(imageS []*entities.ImageSummary) error {
var (
hdr, row string
)
@@ -143,10 +158,11 @@ func writeTemplate(imageS []*entities.ImageSummary, err error) error {
h.Repository, h.Tag = tokenRepoTag(tag)
imgs = append(imgs, h)
}
- if e.IsReadOnly() {
- listFlag.readOnly = true
- }
+ listFlag.readOnly = e.IsReadOnly()
}
+
+ sort.Slice(imgs, sortFunc(listFlag.sort, imgs))
+
if len(listFlag.format) < 1 {
hdr, row = imageListFormat(listFlag)
} else {
@@ -176,37 +192,33 @@ func tokenRepoTag(tag string) (string, string) {
}
}
-func sortFunc(key string, data []*entities.ImageSummary) func(i, j int) bool {
+func sortFunc(key string, data []imageReporter) func(i, j int) bool {
switch key {
case "id":
return func(i, j int) bool {
- return data[i].ID < data[j].ID
+ return data[i].ID() < data[j].ID()
}
case "repository":
return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
+ return data[i].Repository < data[j].Repository
}
case "size":
return func(i, j int) bool {
- return data[i].Size < data[j].Size
+ return data[i].size() < data[j].size()
}
case "tag":
return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
+ return data[i].Tag < data[j].Tag
}
default:
// case "created":
return func(i, j int) bool {
- return data[i].Created.After(data[j].Created)
+ return data[i].created().After(data[j].created())
}
}
}
func imageListFormat(flags listFlagType) (string, string) {
- if flags.quiet {
- return "", "{{.ID}}\n"
- }
-
// Defaults
hdr := "REPOSITORY\tTAG"
row := "{{.Repository}}\t{{if .Tag}}{{.Tag}}{{else}}<none>{{end}}"
@@ -263,6 +275,10 @@ func (i imageReporter) Created() string {
return units.HumanDuration(time.Since(i.ImageSummary.Created)) + " ago"
}
+func (i imageReporter) created() time.Time {
+ return i.ImageSummary.Created
+}
+
func (i imageReporter) Size() string {
s := units.HumanSizeWithPrecision(float64(i.ImageSummary.Size), 3)
j := strings.LastIndexFunc(s, unicode.IsNumber)
@@ -272,3 +288,19 @@ func (i imageReporter) Size() string {
func (i imageReporter) History() string {
return strings.Join(i.ImageSummary.History, ", ")
}
+
+func (i imageReporter) CreatedAt() string {
+ return i.ImageSummary.Created.String()
+}
+
+func (i imageReporter) CreatedSince() string {
+ return i.Created()
+}
+
+func (i imageReporter) CreatedTime() string {
+ return i.CreatedAt()
+}
+
+func (i imageReporter) size() int64 {
+ return i.ImageSummary.Size
+}
diff --git a/cmd/podman/images/rm.go b/cmd/podman/images/rm.go
index da6a90d2b..1cf5fa365 100644
--- a/cmd/podman/images/rm.go
+++ b/cmd/podman/images/rm.go
@@ -54,7 +54,10 @@ func rm(cmd *cobra.Command, args []string) error {
fmt.Println("Untagged: " + u)
}
for _, d := range report.Deleted {
- fmt.Println("Deleted: " + d)
+ // Make sure an image was deleted (and not just untagged); else print it
+ if len(d) > 0 {
+ fmt.Println("Deleted: " + d)
+ }
}
registry.SetExitCode(report.ExitCode)
}
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index 56ca549b6..292c69521 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -96,7 +96,7 @@ func Execute() {
func persistentPreRunE(cmd *cobra.Command, args []string) error {
// TODO: Remove trace statement in podman V2.1
- logrus.Debugf("Called %s.PersistentPreRunE()", cmd.Name())
+ logrus.Debugf("Called %s.PersistentPreRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
cfg := registry.PodmanConfig()
@@ -145,7 +145,7 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
func persistentPostRunE(cmd *cobra.Command, args []string) error {
// TODO: Remove trace statement in podman V2.1
- logrus.Debugf("Called %s.PersistentPostRunE()", cmd.Name())
+ logrus.Debugf("Called %s.PersistentPostRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
cfg := registry.PodmanConfig()
if cmd.Flag("cpu-profile").Changed {
diff --git a/pkg/domain/entities/images.go b/pkg/domain/entities/images.go
index 69af365c0..74f27e25f 100644
--- a/pkg/domain/entities/images.go
+++ b/pkg/domain/entities/images.go
@@ -218,6 +218,7 @@ type ImageSearchReport struct {
Automated string
}
+// Image List Options
type ImageListOptions struct {
All bool `json:"all" schema:"all"`
Filter []string `json:"Filter,omitempty"`
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index 9d6be1b15..be788b2bf 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -469,6 +469,8 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
switch errors.Cause(err) {
case nil:
break
+ case define.ErrNoSuchImage:
+ inUseErrors = true // ExitCode is expected
case storage.ErrImageUsedByContainer:
inUseErrors = true // Important for exit codes in Podman.
return errors.New(
@@ -540,7 +542,7 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
noSuchImageErrors = true // Important for exit codes in Podman.
fallthrough
default:
- deleteError = multierror.Append(deleteError, err)
+ deleteError = multierror.Append(deleteError, errors.Wrapf(err, "failed to remove image '%s'", id))
continue
}
diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go
index 9add915ea..c559e250c 100644
--- a/pkg/domain/infra/abi/images_list.go
+++ b/pkg/domain/infra/abi/images_list.go
@@ -25,8 +25,8 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
return nil, err
}
- summaries := make([]*entities.ImageSummary, len(images))
- for i, img := range images {
+ var summaries []*entities.ImageSummary
+ for _, img := range images {
var repoTags []string
if opts.All {
pairs, err := libpodImage.ReposToMap(img.Names())
@@ -41,6 +41,9 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
}
} else {
repoTags, _ = img.RepoTags()
+ if len(repoTags) == 0 {
+ continue
+ }
}
digests := make([]string, len(img.Digests()))
@@ -72,7 +75,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
sz, _ := img.Size(context.TODO())
e.Size = int64(*sz)
- summaries[i] = &e
+ summaries = append(summaries, &e)
}
return summaries, nil
}
diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go
index 160af1bd5..68f733b41 100644
--- a/test/e2e/common_test.go
+++ b/test/e2e/common_test.go
@@ -1,7 +1,6 @@
package integration
import (
- "encoding/json"
"fmt"
"io/ioutil"
"math/rand"
@@ -21,9 +20,10 @@ import (
"github.com/containers/storage"
"github.com/containers/storage/pkg/reexec"
"github.com/containers/storage/pkg/stringid"
+ jsoniter "github.com/json-iterator/go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
- "github.com/onsi/gomega/gexec"
+ . "github.com/onsi/gomega/gexec"
"github.com/pkg/errors"
)
@@ -314,7 +314,7 @@ func (p *PodmanTestIntegration) createArtifact(image string) {
// image and returns json
func (s *PodmanSessionIntegration) InspectImageJSON() []inspect.ImageData {
var i []inspect.ImageData
- err := json.Unmarshal(s.Out.Contents(), &i)
+ err := jsoniter.Unmarshal(s.Out.Contents(), &i)
Expect(err).To(BeNil())
return i
}
@@ -324,7 +324,7 @@ func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectCo
cmd := []string{"inspect", name}
session := p.Podman(cmd)
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
return session.InspectContainerToJSON()
}
@@ -419,7 +419,7 @@ func (p *PodmanTestIntegration) PodmanPID(args []string) (*PodmanSessionIntegrat
podmanOptions := p.MakeOptions(args, false, false)
fmt.Printf("Running: %s %s\n", p.PodmanBinary, strings.Join(podmanOptions, " "))
command := exec.Command(p.PodmanBinary, podmanOptions...)
- session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
+ session, err := Start(command, GinkgoWriter, GinkgoWriter)
if err != nil {
Fail(fmt.Sprintf("unable to run podman command: %s", strings.Join(podmanOptions, " ")))
}
@@ -494,7 +494,7 @@ func (p *PodmanTestIntegration) PullImage(image string) error {
// container and returns json
func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectContainerData {
var i []define.InspectContainerData
- err := json.Unmarshal(s.Out.Contents(), &i)
+ err := jsoniter.Unmarshal(s.Out.Contents(), &i)
Expect(err).To(BeNil())
return i
}
@@ -502,7 +502,7 @@ func (s *PodmanSessionIntegration) InspectContainerToJSON() []define.InspectCont
// InspectPodToJSON takes the sessions output from a pod inspect and returns json
func (s *PodmanSessionIntegration) InspectPodToJSON() define.InspectPodData {
var i define.InspectPodData
- err := json.Unmarshal(s.Out.Contents(), &i)
+ err := jsoniter.Unmarshal(s.Out.Contents(), &i)
Expect(err).To(BeNil())
return i
}
diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go
index c0165e060..d7295b67a 100644
--- a/test/e2e/images_test.go
+++ b/test/e2e/images_test.go
@@ -10,6 +10,7 @@ import (
"github.com/docker/go-units"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/gexec"
)
var _ = Describe("Podman images", func() {
@@ -20,7 +21,6 @@ var _ = Describe("Podman images", func() {
)
BeforeEach(func() {
- Skip(v2fail)
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)
@@ -39,7 +39,7 @@ var _ = Describe("Podman images", func() {
It("podman images", func() {
session := podmanTest.Podman([]string{"images"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 2))
Expect(session.LineInOuputStartsWith("docker.io/library/alpine")).To(BeTrue())
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
@@ -48,11 +48,11 @@ var _ = Describe("Podman images", func() {
It("podman images with no images prints header", func() {
rmi := podmanTest.PodmanNoCache([]string{"rmi", "-a"})
rmi.WaitWithDefaultTimeout()
- Expect(rmi.ExitCode()).To(Equal(0))
+ Expect(rmi).Should(Exit(0))
session := podmanTest.PodmanNoCache([]string{"images"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(1))
Expect(session.LineInOutputContains("REPOSITORY")).To(BeTrue())
})
@@ -60,7 +60,7 @@ var _ = Describe("Podman images", func() {
It("podman image List", func() {
session := podmanTest.Podman([]string{"image", "list"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 2))
Expect(session.LineInOuputStartsWith("docker.io/library/alpine")).To(BeTrue())
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
@@ -71,15 +71,15 @@ var _ = Describe("Podman images", func() {
podmanTest.RestoreAllArtifacts()
session := podmanTest.PodmanNoCache([]string{"tag", ALPINE, "foo:a", "foo:b", "foo:c"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
// tag "foo:c" to "bar:{a,b}"
session = podmanTest.PodmanNoCache([]string{"tag", "foo:c", "bar:a", "bar:b"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
// check all previous and the newly tagged images
session = podmanTest.PodmanNoCache([]string{"images"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
session.LineInOutputContainsTag("docker.io/library/alpine", "latest")
session.LineInOutputContainsTag("docker.io/library/busybox", "glibc")
session.LineInOutputContainsTag("foo", "a")
@@ -89,14 +89,14 @@ var _ = Describe("Podman images", func() {
session.LineInOutputContainsTag("bar", "b")
session = podmanTest.PodmanNoCache([]string{"images", "-qn"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically("==", 2))
})
It("podman images with digests", func() {
session := podmanTest.Podman([]string{"images", "--digests"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 2))
Expect(session.LineInOuputStartsWith("docker.io/library/alpine")).To(BeTrue())
Expect(session.LineInOuputStartsWith("docker.io/library/busybox")).To(BeTrue())
@@ -105,14 +105,14 @@ var _ = Describe("Podman images", func() {
It("podman empty images list in JSON format", func() {
session := podmanTest.Podman([]string{"images", "--format=json", "not-existing-image"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})
It("podman images in JSON format", func() {
session := podmanTest.Podman([]string{"images", "--format=json"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})
@@ -120,13 +120,13 @@ var _ = Describe("Podman images", func() {
formatStr := "{{.ID}}\t{{.Created}}\t{{.CreatedAt}}\t{{.CreatedSince}}\t{{.CreatedTime}}"
session := podmanTest.Podman([]string{"images", fmt.Sprintf("--format=%s", formatStr)})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
})
It("podman images with short options", func() {
session := podmanTest.Podman([]string{"images", "-qn"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 1))
})
@@ -134,19 +134,19 @@ var _ = Describe("Podman images", func() {
podmanTest.RestoreAllArtifacts()
session := podmanTest.PodmanNoCache([]string{"images", "-q", ALPINE})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(1))
session = podmanTest.PodmanNoCache([]string{"tag", ALPINE, "foo:a"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
session = podmanTest.PodmanNoCache([]string{"tag", BB, "foo:b"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
session = podmanTest.PodmanNoCache([]string{"images", "-q", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(2))
})
@@ -157,24 +157,24 @@ var _ = Describe("Podman images", func() {
podmanTest.RestoreAllArtifacts()
result := podmanTest.PodmanNoCache([]string{"images", "-q", "-f", "reference=docker.io*"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray())).To(Equal(2))
retapline := podmanTest.PodmanNoCache([]string{"images", "-f", "reference=a*pine"})
retapline.WaitWithDefaultTimeout()
- Expect(retapline.ExitCode()).To(Equal(0))
+ Expect(retapline).Should(Exit(0))
Expect(len(retapline.OutputToStringArray())).To(Equal(2))
Expect(retapline.LineInOutputContains("alpine")).To(BeTrue())
retapline = podmanTest.PodmanNoCache([]string{"images", "-f", "reference=alpine"})
retapline.WaitWithDefaultTimeout()
- Expect(retapline.ExitCode()).To(Equal(0))
+ Expect(retapline).Should(Exit(0))
Expect(len(retapline.OutputToStringArray())).To(Equal(2))
Expect(retapline.LineInOutputContains("alpine")).To(BeTrue())
retnone := podmanTest.PodmanNoCache([]string{"images", "-q", "-f", "reference=bogus"})
retnone.WaitWithDefaultTimeout()
- Expect(retnone.ExitCode()).To(Equal(0))
+ Expect(retnone).Should(Exit(0))
Expect(len(retnone.OutputToStringArray())).To(Equal(0))
})
@@ -188,7 +188,7 @@ RUN apk update && apk add man
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.Podman([]string{"images", "-q", "-f", "before=foobar.com/before:latest"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray()) >= 1).To(BeTrue())
})
@@ -199,14 +199,14 @@ RUN apk update && apk add man
podmanTest.RestoreAllArtifacts()
rmi := podmanTest.PodmanNoCache([]string{"rmi", "busybox"})
rmi.WaitWithDefaultTimeout()
- Expect(rmi.ExitCode()).To(Equal(0))
+ Expect(rmi).Should(Exit(0))
dockerfile := `FROM docker.io/library/alpine:latest
`
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.PodmanNoCache([]string{"images", "-q", "-f", "after=docker.io/library/alpine:latest"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray())).To(Equal(0))
})
@@ -217,14 +217,14 @@ RUN apk update && apk add man
podmanTest.RestoreAllArtifacts()
rmi := podmanTest.PodmanNoCache([]string{"image", "rm", "busybox"})
rmi.WaitWithDefaultTimeout()
- Expect(rmi.ExitCode()).To(Equal(0))
+ Expect(rmi).Should(Exit(0))
dockerfile := `FROM docker.io/library/alpine:latest
`
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.PodmanNoCache([]string{"image", "list", "-q", "-f", "after=docker.io/library/alpine:latest"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray())).To(Equal(0))
})
@@ -238,7 +238,7 @@ RUN apk update && apk add man
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.Podman([]string{"images", "-q", "-f", "dangling=true"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
Expect(len(result.OutputToStringArray())).To(Equal(0))
})
@@ -248,13 +248,13 @@ RUN apk update && apk add man
}
session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
imageData := session.InspectImageJSON()
- result := podmanTest.Podman([]string{"images", fmt.Sprintf("sha256:%s", imageData[0].ID)})
+ result := podmanTest.Podman([]string{"images", "sha256:" + imageData[0].ID})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
})
It("podman check for image with sha256: prefix", func() {
@@ -263,13 +263,13 @@ RUN apk update && apk add man
}
session := podmanTest.Podman([]string{"image", "inspect", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
imageData := session.InspectImageJSON()
result := podmanTest.Podman([]string{"image", "ls", fmt.Sprintf("sha256:%s", imageData[0].ID)})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
})
It("podman images sort by values", func() {
@@ -277,7 +277,7 @@ RUN apk update && apk add man
f := fmt.Sprintf("{{.%s}}", format)
session := podmanTest.Podman([]string{"images", "--sort", value, "--format", f})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(result))
+ Expect(session).Should(Exit(result))
return session.OutputToStringArray()
}
@@ -298,7 +298,9 @@ RUN apk update && apk add man
return size1 < size2
})).To(BeTrue())
sortedArr = sortValueTest("tag", 0, "Tag")
- Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue())
+ Expect(sort.SliceIsSorted(sortedArr,
+ func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).
+ To(BeTrue())
sortValueTest("badvalue", 125, "Tag")
sortValueTest("id", 125, "badvalue")
@@ -317,12 +319,12 @@ ENV foo=bar
podmanTest.BuildImage(dockerfile, "test", "true")
session := podmanTest.PodmanNoCache([]string{"images"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(4))
session2 := podmanTest.PodmanNoCache([]string{"images", "--all"})
session2.WaitWithDefaultTimeout()
- Expect(session2.ExitCode()).To(Equal(0))
+ Expect(session2).Should(Exit(0))
Expect(len(session2.OutputToStringArray())).To(Equal(6))
})
@@ -335,7 +337,7 @@ LABEL "com.example.vendor"="Example Vendor"
podmanTest.BuildImage(dockerfile, "test", "true")
session := podmanTest.Podman([]string{"images", "-f", "label=version=1.0"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(2))
})
@@ -357,52 +359,52 @@ LABEL "com.example.vendor"="Example Vendor"
session := podmanTest.Podman([]string{"images", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output := session.OutputToString()
Expect(output).To(Not(MatchRegexp("<missing>")))
Expect(output).To(Not(MatchRegexp("error")))
session = podmanTest.Podman([]string{"image", "tree", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(MatchRegexp("No Image Layers"))
session = podmanTest.Podman([]string{"history", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(Not(MatchRegexp("error")))
session = podmanTest.Podman([]string{"history", "--quiet", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
Expect(len(session.OutputToStringArray())).To(Equal(6))
session = podmanTest.Podman([]string{"image", "list", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(Not(MatchRegexp("<missing>")))
Expect(output).To(Not(MatchRegexp("error")))
session = podmanTest.Podman([]string{"image", "list"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(Not(MatchRegexp("<missing>")))
Expect(output).To(Not(MatchRegexp("error")))
session = podmanTest.Podman([]string{"inspect", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(Not(MatchRegexp("<missing>")))
Expect(output).To(Not(MatchRegexp("error")))
session = podmanTest.Podman([]string{"inspect", "--format", "{{.RootFS.Layers}}", "foo"})
session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
+ Expect(session).Should(Exit(0))
output = session.OutputToString()
Expect(output).To(Equal("[]"))
})
@@ -414,11 +416,11 @@ LABEL "com.example.vendor"="Example Vendor"
podmanTest.BuildImage(dockerfile, "foobar.com/before:latest", "false")
result := podmanTest.Podman([]string{"images", "-f", "readonly=true"})
result.WaitWithDefaultTimeout()
- Expect(result.ExitCode()).To(Equal(0))
+ Expect(result).Should(Exit(0))
result1 := podmanTest.Podman([]string{"images", "--filter", "readonly=false"})
result1.WaitWithDefaultTimeout()
- Expect(result1.ExitCode()).To(Equal(0))
+ Expect(result1).Should(Exit(0))
Expect(result.OutputToStringArray()).To(Not(Equal(result1.OutputToStringArray())))
})
diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go
index d556cbc72..6c0b01bd5 100644
--- a/test/e2e/rmi_test.go
+++ b/test/e2e/rmi_test.go
@@ -141,12 +141,13 @@ var _ = Describe("Podman rmi", func() {
session = podmanTest.PodmanNoCache([]string{"images", "-q", "-a"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
- Expect(len(session.OutputToStringArray())).To(Equal(2))
- untaggedImg := session.OutputToStringArray()[1]
+ Expect(len(session.OutputToStringArray())).To(Equal(2),
+ "Output from 'podman images -q -a':'%s'", session.Out.Contents())
+ untaggedImg := session.OutputToStringArray()[0]
session = podmanTest.PodmanNoCache([]string{"rmi", "-f", untaggedImg})
session.WaitWithDefaultTimeout()
- Expect(session).Should(Exit(2))
+ Expect(session).Should(Exit(2), "UntaggedImg is '%s'", untaggedImg)
})
It("podman rmi image that is created from another named imaged", func() {
diff --git a/test/utils/utils.go b/test/utils/utils.go
index 6ab8604a4..0131e023d 100644
--- a/test/utils/utils.go
+++ b/test/utils/utils.go
@@ -206,7 +206,7 @@ func WaitContainerReady(p PodmanTestCommon, id string, expStr string, timeout in
// OutputToString formats session output to string
func (s *PodmanSession) OutputToString() string {
- fields := strings.Fields(fmt.Sprintf("%s", s.Out.Contents()))
+ fields := strings.Fields(string(s.Out.Contents()))
return strings.Join(fields, " ")
}