diff options
author | baude <bbaude@redhat.com> | 2019-01-31 13:20:04 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-08 10:26:43 -0600 |
commit | 25a3923b61a5ca014318e6d957f68abd03947297 (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/run_test.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
download | podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2 podman-25a3923b61a5ca014318e6d957f68abd03947297.zip |
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the
project is more well maintained. There are also some technical reasons
as well which extend into our remote client work.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/run_test.go')
-rw-r--r-- | cmd/podman/run_test.go | 57 |
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()) } |