Skip to content

Commit

Permalink
Merge pull request #2477 from rhatdan/test
Browse files Browse the repository at this point in the history
Add tests to make sure podman container and podman image commands work
  • Loading branch information
openshift-merge-robot authored Mar 3, 2019
2 parents 9adcda7 + d231cfb commit f3a3d8e
Show file tree
Hide file tree
Showing 25 changed files with 372 additions and 64 deletions.
4 changes: 0 additions & 4 deletions cmd/podman/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ func getImageSubCommands() []*cobra.Command {
// Commands that the local client implements
func getContainerSubCommands() []*cobra.Command {

var _listSubCommand = _psCommand
_listSubCommand.Use = "list"

return []*cobra.Command{
_attachCommand,
_checkpointCommand,
Expand All @@ -68,7 +65,6 @@ func getContainerSubCommands() []*cobra.Command {
_execCommand,
_exportCommand,
_killCommand,
&_listSubCommand,
_logsCommand,
_mountCommand,
_pauseCommand,
Expand Down
50 changes: 36 additions & 14 deletions cmd/podman/container.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
package main

import (
"strings"

"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/spf13/cobra"
)

var containerDescription = "Manage containers"
var containerCommand = cliconfig.PodmanCommand{
Command: &cobra.Command{
Use: "container",
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
},
}
var (
containerDescription = "Manage containers"
containerCommand = cliconfig.PodmanCommand{
Command: &cobra.Command{
Use: "container",
Short: "Manage Containers",
Long: containerDescription,
TraverseChildren: true,
},
}

// Commands that are universally implemented.
var containerCommands = []*cobra.Command{
_containerExistsCommand,
_inspectCommand,
}
listSubCommand cliconfig.PsValues
_listSubCommand = &cobra.Command{
Use: strings.Replace(_psCommand.Use, "ps", "list", 1),
Short: _psCommand.Short,
Long: _psCommand.Long,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
listSubCommand.InputArgs = args
listSubCommand.GlobalFlags = MainGlobalOpts
return psCmd(&listSubCommand)
},
Example: strings.Replace(_psCommand.Example, "podman ps", "podman container list", -1),
}

// Commands that are universally implemented.
containerCommands = []*cobra.Command{
_containerExistsCommand,
_inspectCommand,
_listSubCommand,
}
)

func init() {
listSubCommand.Command = _listSubCommand
psInit(&listSubCommand)

containerCommand.AddCommand(containerCommands...)
containerCommand.AddCommand(getContainerSubCommands()...)
containerCommand.SetUsageTemplate(UsageTemplate())
Expand Down
46 changes: 34 additions & 12 deletions cmd/podman/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,60 @@ var (
Long: imageDescription,
},
}
_imagesSubCommand = _imagesCommand
_rmSubCommand = _rmiCommand
imagesSubCommand cliconfig.ImagesValues
_imagesSubCommand = &cobra.Command{
Use: strings.Replace(_imagesCommand.Use, "images", "list", 1),
Short: _imagesCommand.Short,
Long: _imagesCommand.Long,
Aliases: []string{"ls"},
RunE: func(cmd *cobra.Command, args []string) error {
imagesSubCommand.InputArgs = args
imagesSubCommand.GlobalFlags = MainGlobalOpts
return imagesCmd(&imagesSubCommand)
},
Example: strings.Replace(_imagesCommand.Example, "podman images", "podman image list", -1),
}

rmSubCommand cliconfig.RmiValues
_rmSubCommand = &cobra.Command{
Use: strings.Replace(_rmiCommand.Use, "rmi", "rm", 1),
Short: _rmiCommand.Short,
Long: _rmiCommand.Long,
RunE: func(cmd *cobra.Command, args []string) error {
rmSubCommand.InputArgs = args
rmSubCommand.GlobalFlags = MainGlobalOpts
return rmiCmd(&rmSubCommand)
},
Example: strings.Replace(_rmiCommand.Example, "podman rmi", "podman image rm", -1),
}
)

//imageSubCommands are implemented both in local and remote clients
var imageSubCommands = []*cobra.Command{
_buildCommand,
_historyCommand,
_imagesSubCommand,
_imageExistsCommand,
_importCommand,
_inspectCommand,
_loadCommand,
_pruneImagesCommand,
_pullCommand,
_pushCommand,
_rmSubCommand,
_saveCommand,
_tagCommand,
}

func init() {
rmSubCommand.Command = _rmSubCommand
rmiInit(&rmSubCommand)

imagesSubCommand.Command = _imagesSubCommand
imagesInit(&imagesSubCommand)

imageCommand.SetUsageTemplate(UsageTemplate())
imageCommand.AddCommand(imageSubCommands...)
imageCommand.AddCommand(getImageSubCommands()...)

// Setup of "images" to appear as "list"
_imagesSubCommand.Use = strings.Replace(_imagesSubCommand.Use, "images", "list", 1)
_imagesSubCommand.Aliases = []string{"ls"}
_imagesSubCommand.Example = strings.Replace(_imagesSubCommand.Example, "podman images", "podman image list", -1)
imageCommand.AddCommand(&_imagesSubCommand)

// It makes no sense to keep 'podman images rmi'; just use 'rm'
_rmSubCommand.Use = strings.Replace(_rmSubCommand.Use, "rmi", "rm", 1)
_rmSubCommand.Example = strings.Replace(_rmSubCommand.Example, "podman rmi", "podman image rm", -1)
imageCommand.AddCommand(&_rmSubCommand)
}
30 changes: 17 additions & 13 deletions cmd/podman/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,26 @@ var (
}
)

func init() {
imagesCommand.Command = &_imagesCommand
imagesCommand.SetUsageTemplate(UsageTemplate())

flags := imagesCommand.Flags()
flags.BoolVarP(&imagesCommand.All, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&imagesCommand.Digests, "digests", false, "Show digests")
flags.StringSliceVarP(&imagesCommand.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringVar(&imagesCommand.Format, "format", "", "Change the output format to JSON or a Go template")
flags.BoolVarP(&imagesCommand.Noheading, "noheading", "n", false, "Do not print column headings")
func imagesInit(command *cliconfig.ImagesValues) {
command.SetUsageTemplate(UsageTemplate())

flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Show all images (default hides intermediate images)")
flags.BoolVar(&command.Digests, "digests", false, "Show digests")
flags.StringSliceVarP(&command.Filter, "filter", "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringVar(&command.Format, "format", "", "Change the output format to JSON or a Go template")
flags.BoolVarP(&command.Noheading, "noheading", "n", false, "Do not print column headings")
// TODO Need to learn how to deal with second name being a string instead of a char.
// This needs to be "no-trunc, notruncate"
flags.BoolVar(&imagesCommand.NoTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVarP(&imagesCommand.Quiet, "quiet", "q", false, "Display only image IDs")
flags.StringVar(&imagesCommand.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")
flags.BoolVar(&command.NoTrunc, "no-trunc", false, "Do not truncate output")
flags.BoolVarP(&command.Quiet, "quiet", "q", false, "Display only image IDs")
flags.StringVar(&command.Sort, "sort", "created", "Sort by created, id, repository, size, or tag")

}

func init() {
imagesCommand.Command = &_imagesCommand
imagesInit(&imagesCommand)
}

func imagesCmd(c *cliconfig.ImagesValues) error {
Expand Down
38 changes: 21 additions & 17 deletions cmd/podman/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,31 @@ var (
}
)

func init() {
psCommand.Command = &_psCommand
psCommand.SetUsageTemplate(UsageTemplate())
flags := psCommand.Flags()
flags.BoolVarP(&psCommand.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&psCommand.Filter, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&psCommand.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&psCommand.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVarP(&psCommand.Latest, "latest", "l", false, "Show the latest container created (all states)")
flags.BoolVar(&psCommand.Namespace, "namespace", false, "Display namespace information")
flags.BoolVar(&psCommand.Namespace, "ns", false, "Display namespace information")
flags.BoolVar(&psCommand.NoTrunct, "no-trunc", false, "Display the extended information")
flags.BoolVarP(&psCommand.Pod, "pod", "p", false, "Print the ID and name of the pod the containers are associated with")
flags.BoolVarP(&psCommand.Quiet, "quiet", "q", false, "Print the numeric IDs of the containers only")
flags.BoolVarP(&psCommand.Size, "size", "s", false, "Display the total file sizes")
flags.StringVar(&psCommand.Sort, "sort", "created", "Sort output by command, created, id, image, names, runningfor, size, or status")
flags.BoolVar(&psCommand.Sync, "sync", false, "Sync container state with OCI runtime")
func psInit(command *cliconfig.PsValues) {
command.SetUsageTemplate(UsageTemplate())
flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Show all the containers, default is only running containers")
flags.StringSliceVarP(&command.Filter, "filter", "f", []string{}, "Filter output based on conditions given")
flags.StringVar(&command.Format, "format", "", "Pretty-print containers to JSON or using a Go template")
flags.IntVarP(&command.Last, "last", "n", -1, "Print the n last created containers (all states)")
flags.BoolVarP(&command.Latest, "latest", "l", false, "Show the latest container created (all states)")
flags.BoolVar(&command.Namespace, "namespace", false, "Display namespace information")
flags.BoolVar(&command.Namespace, "ns", false, "Display namespace information")
flags.BoolVar(&command.NoTrunct, "no-trunc", false, "Display the extended information")
flags.BoolVarP(&command.Pod, "pod", "p", false, "Print the ID and name of the pod the containers are associated with")
flags.BoolVarP(&command.Quiet, "quiet", "q", false, "Print the numeric IDs of the containers only")
flags.BoolVarP(&command.Size, "size", "s", false, "Display the total file sizes")
flags.StringVar(&command.Sort, "sort", "created", "Sort output by command, created, id, image, names, runningfor, size, or status")
flags.BoolVar(&command.Sync, "sync", false, "Sync container state with OCI runtime")

markFlagHiddenForRemoteClient("latest", flags)
}

func init() {
psCommand.Command = &_psCommand
psInit(&psCommand)
}

func psCmd(c *cliconfig.PsValues) error {
if c.Bool("trace") {
span, _ := opentracing.StartSpanFromContext(Ctx, "psCmd")
Expand Down
12 changes: 8 additions & 4 deletions cmd/podman/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ var (
}
)

func rmiInit(command *cliconfig.RmiValues) {
command.SetUsageTemplate(UsageTemplate())
flags := command.Flags()
flags.BoolVarP(&command.All, "all", "a", false, "Remove all images")
flags.BoolVarP(&command.Force, "force", "f", false, "Force Removal of the image")
}

func init() {
rmiCommand.Command = &_rmiCommand
rmiCommand.SetUsageTemplate(UsageTemplate())
flags := rmiCommand.Flags()
flags.BoolVarP(&rmiCommand.All, "all", "a", false, "Remove all images")
flags.BoolVarP(&rmiCommand.Force, "force", "f", false, "Force Removal of the image")
rmiInit(&rmiCommand)
}

func rmiCmd(c *cliconfig.RmiValues) error {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ var _ = Describe("Podman attach", func() {
Expect(results.ExitCode()).To(Equal(125))
})

It("podman container attach to non-running container", func() {
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-d", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

results := podmanTest.Podman([]string{"container", "attach", "test1"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
})

It("podman attach to multiple containers", func() {
session := podmanTest.RunTopContainer("test1")
session.WaitWithDefaultTimeout()
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ var _ = Describe("Podman commit", func() {
Expect(StringInSlice("foobar.com/test1-image:latest", data[0].RepoTags)).To(BeTrue())
})

It("podman container commit container", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(1))

session := podmanTest.Podman([]string{"container", "commit", "test1", "foobar.com/test1-image:latest"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

check := podmanTest.Podman([]string{"container", "inspect", "foobar.com/test1-image:latest"})
check.WaitWithDefaultTimeout()
data := check.InspectImageJSON()
Expect(StringInSlice("foobar.com/test1-image:latest", data[0].RepoTags)).To(BeTrue())
})

It("podman commit container with message", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ var _ = Describe("Podman create", func() {
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
})

It("podman container create container based on a remote image", func() {
session := podmanTest.Podman([]string{"container", "create", BB_GLIBC, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
})

It("podman create using short options", func() {
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ var _ = Describe("Podman diff", func() {
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})

It("podman container diff of image", func() {
session := podmanTest.Podman([]string{"container", "diff", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})

It("podman diff bogus image", func() {
session := podmanTest.Podman([]string{"diff", "1234"})
session.WaitWithDefaultTimeout()
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ var _ = Describe("Podman exec", func() {
Expect(session.ExitCode()).To(Equal(0))
})

It("podman container exec simple command", func() {
setup := podmanTest.RunTopContainer("test1")
setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0))

session := podmanTest.Podman([]string{"container", "exec", "test1", "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})

It("podman exec simple command using latest", func() {
setup := podmanTest.RunTopContainer("test1")
setup.WaitWithDefaultTimeout()
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ var _ = Describe("Podman export", func() {
Expect(err).To(BeNil())
})

It("podman container export output flag", func() {
SkipIfRemote()
_, ec, cid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))

outfile := filepath.Join(podmanTest.TempDir, "container.tar")
result := podmanTest.Podman([]string{"container", "export", "-o", outfile, cid})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
_, err := os.Stat(outfile)
Expect(err).To(BeNil())

err = os.Remove(outfile)
Expect(err).To(BeNil())
})

It("podman export bad filename", func() {
_, ec, cid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
Expand Down
Loading

0 comments on commit f3a3d8e

Please sign in to comment.