Skip to content

Commit

Permalink
copy and move
Browse files Browse the repository at this point in the history
  • Loading branch information
lingrino committed Jun 11, 2020
1 parent 0950aa9 commit 033e22f
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/path.go
Expand Up @@ -32,6 +32,8 @@ func (c *cli) newPathCmd() *cobra.Command {
c.newPathWriteCmd(),
c.newPathDeleteCmd(),
c.newPathSearchCmd(),
c.newPathCopyCmd(),
c.newPathMoveCmd(),
)

return cmd
Expand Down
31 changes: 31 additions & 0 deletions cmd/path_copy.go
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/spf13/cobra"
)

const (
pathCopyUse = "copy <source path> <destination path>"
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])
}
41 changes: 41 additions & 0 deletions 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())
})
}
}
31 changes: 31 additions & 0 deletions cmd/path_move.go
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/spf13/cobra"
)

const (
pathMoveUse = "move <source path> <destination path>"
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])
}
41 changes: 41 additions & 0 deletions 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())
})
}
}

0 comments on commit 033e22f

Please sign in to comment.