From 033e22f2e211a54ace869d804a5913db0da49acf Mon Sep 17 00:00:00 2001 From: Sean Lingren Date: Wed, 10 Jun 2020 22:29:34 -0500 Subject: [PATCH] copy and move --- cmd/path.go | 2 ++ cmd/path_copy.go | 31 +++++++++++++++++++++++++++++++ cmd/path_copy_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ cmd/path_move.go | 31 +++++++++++++++++++++++++++++++ cmd/path_move_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 cmd/path_copy.go create mode 100644 cmd/path_copy_test.go create mode 100644 cmd/path_move.go create mode 100644 cmd/path_move_test.go diff --git a/cmd/path.go b/cmd/path.go index 650b56c9..8cea1013 100644 --- a/cmd/path.go +++ b/cmd/path.go @@ -32,6 +32,8 @@ func (c *cli) newPathCmd() *cobra.Command { c.newPathWriteCmd(), c.newPathDeleteCmd(), c.newPathSearchCmd(), + c.newPathCopyCmd(), + c.newPathMoveCmd(), ) return cmd diff --git a/cmd/path_copy.go b/cmd/path_copy.go new file mode 100644 index 00000000..379e9779 --- /dev/null +++ b/cmd/path_copy.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +const ( + pathCopyUse = "copy " + pathCopyShort = "Copy a secret from a source path to a destination path" + pathCopyExample = "vaku path copy secret/foo secret/bar" + pathCopyLong = "Search a secret for a string" +) + +func (c *cli) newPathCopyCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: pathCopyUse, + Short: pathCopyShort, + Long: pathCopyLong, + Example: pathCopyExample, + + Args: cobra.ExactArgs(2), //nolint:gomnd + + RunE: c.runPathCopy, + } + + return cmd +} + +func (c *cli) runPathCopy(cmd *cobra.Command, args []string) error { + return c.vc.PathCopy(args[0], args[1]) +} diff --git a/cmd/path_copy_test.go b/cmd/path_copy_test.go new file mode 100644 index 00000000..5607789c --- /dev/null +++ b/cmd/path_copy_test.go @@ -0,0 +1,41 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPathCopy(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + giveArgs []string + wantOut string + wantErr string + }{ + { + name: "foo", + giveArgs: []string{"foo", "bar"}, + wantOut: "", + wantErr: "", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + args := append([]string{"path", "copy"}, tt.giveArgs...) + cli, outW, errW := newTestCLIWithAPI(t, args) + + ec := cli.execute() + assert.Equal(t, ec*len(errW.String()), len(errW.String()), "unexpected exit code") + + assert.Equal(t, tt.wantOut, outW.String()) + assert.Equal(t, tt.wantErr, errW.String()) + }) + } +} diff --git a/cmd/path_move.go b/cmd/path_move.go new file mode 100644 index 00000000..0026e042 --- /dev/null +++ b/cmd/path_move.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +const ( + pathMoveUse = "move " + pathMoveShort = "Move a secret from a source path to a destination path" + pathMoveExample = "vaku path move secret/foo secret/bar" + pathMoveLong = "Search a secret for a string" +) + +func (c *cli) newPathMoveCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: pathMoveUse, + Short: pathMoveShort, + Long: pathMoveLong, + Example: pathMoveExample, + + Args: cobra.ExactArgs(2), //nolint:gomnd + + RunE: c.runPathMove, + } + + return cmd +} + +func (c *cli) runPathMove(cmd *cobra.Command, args []string) error { + return c.vc.PathMove(args[0], args[1]) +} diff --git a/cmd/path_move_test.go b/cmd/path_move_test.go new file mode 100644 index 00000000..fa6d5159 --- /dev/null +++ b/cmd/path_move_test.go @@ -0,0 +1,41 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPathMove(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + giveArgs []string + wantOut string + wantErr string + }{ + { + name: "foo", + giveArgs: []string{"foo", "bar"}, + wantOut: "", + wantErr: "", + }, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + args := append([]string{"path", "move"}, tt.giveArgs...) + cli, outW, errW := newTestCLIWithAPI(t, args) + + ec := cli.execute() + assert.Equal(t, ec*len(errW.String()), len(errW.String()), "unexpected exit code") + + assert.Equal(t, tt.wantOut, outW.String()) + assert.Equal(t, tt.wantErr, errW.String()) + }) + } +}