Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
}) | ||
} | ||
} |