summaryrefslogtreecommitdiff
path: root/cmd/podman/run_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-08 20:12:38 +0100
committerGitHub <noreply@github.com>2019-02-08 20:12:38 +0100
commitafd4d5f4a4b05f421e6f336b4d74a0d808be57ed (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/run_test.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
parent25a3923b61a5ca014318e6d957f68abd03947297 (diff)
downloadpodman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.gz
podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.tar.bz2
podman-afd4d5f4a4b05f421e6f336b4d74a0d808be57ed.zip
Merge pull request #2274 from baude/cobraprep
Migrate to cobra CLI
Diffstat (limited to 'cmd/podman/run_test.go')
-rw-r--r--cmd/podman/run_test.go57
1 files changed, 30 insertions, 27 deletions
diff --git a/cmd/podman/run_test.go b/cmd/podman/run_test.go
index 33c0a4bfe..5ea39e457 100644
--- a/cmd/podman/run_test.go
+++ b/cmd/podman/run_test.go
@@ -4,24 +4,19 @@ import (
"runtime"
"testing"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/pkg/inspect"
cc "github.com/containers/libpod/pkg/spec"
- units "github.com/docker/go-units"
+ "github.com/docker/go-units"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
- "github.com/urfave/cli"
)
var (
- cmd = []string{"podman", "test", "alpine"}
- CLI *cli.Context
- testCommand = cli.Command{
- Name: "test",
- Flags: sortFlags(createFlags),
- Action: testCmd,
- HideHelp: true,
- }
+ cmd = []string{"podman", "test", "alpine"}
+ CLI *cliconfig.PodmanCommand
)
// generates a mocked ImageData structure based on alpine
@@ -53,23 +48,29 @@ func generateAlpineImageData() *inspect.ImageData {
}
// sets a global CLI
-func testCmd(c *cli.Context) error {
- CLI = c
+func testCmd(c *cobra.Command) error {
+ CLI = &cliconfig.PodmanCommand{Command: c}
return nil
}
// creates the mocked cli pointing to our create flags
// global flags like log-level are not implemented
-func createCLI() cli.App {
- a := cli.App{
- Commands: []cli.Command{
- testCommand,
+func createCLI(args []string) *cliconfig.PodmanCommand {
+ var testCommand = &cliconfig.PodmanCommand{
+ Command: &cobra.Command{
+ Use: "test",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ return testCmd(cmd)
+ },
},
}
- return a
+ rootCmd := testCommand
+ getCreateFlags(rootCmd)
+ rootCmd.ParseFlags(args)
+ return rootCmd
}
-func getRuntimeSpec(c *cli.Context) (*spec.Spec, error) {
+func getRuntimeSpec(c *cliconfig.PodmanCommand) (*spec.Spec, error) {
/*
TODO: This test has never worked. Need to install content
runtime, err := getRuntime(c)
@@ -98,10 +99,11 @@ func TestPIDsLimit(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("seccomp, which is enabled by default, is only supported on Linux")
}
- a := createCLI()
args := []string{"--pids-limit", "22"}
- a.Run(append(cmd, args...))
- runtimeSpec, err := getRuntimeSpec(CLI)
+ a := createCLI(args)
+ a.InputArgs = args
+ //a.Run(append(cmd, args...))
+ runtimeSpec, err := getRuntimeSpec(a)
if err != nil {
t.Fatalf(err.Error())
}
@@ -116,10 +118,10 @@ func TestBLKIOWeightDevice(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("seccomp, which is enabled by default, is only supported on Linux")
}
- a := createCLI()
args := []string{"--blkio-weight-device", "/dev/zero:100"}
- a.Run(append(cmd, args...))
- runtimeSpec, err := getRuntimeSpec(CLI)
+ a := createCLI(args)
+ a.InputArgs = args
+ runtimeSpec, err := getRuntimeSpec(a)
if err != nil {
t.Fatalf(err.Error())
}
@@ -134,10 +136,11 @@ func TestMemorySwap(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("seccomp, which is enabled by default, is only supported on Linux")
}
- a := createCLI()
args := []string{"--memory-swap", "45m", "--memory", "40m"}
- a.Run(append(cmd, args...))
- runtimeSpec, err := getRuntimeSpec(CLI)
+ a := createCLI(args)
+ a.InputArgs = args
+ //a.Run(append(cmd, args...))
+ runtimeSpec, err := getRuntimeSpec(a)
if err != nil {
t.Fatalf(err.Error())
}