Add "policy" subcommand

This commit is contained in:
Seth Vargo
2017-09-07 22:00:21 -04:00
parent d695dbf111
commit a34b2dae9f
11 changed files with 761 additions and 97 deletions

View File

@@ -29,16 +29,10 @@ func TestPolicyListCommand_Run(t *testing.T) {
}{
{
"too_many_args",
[]string{"foo", "bar"},
[]string{"foo"},
"Too many arguments",
1,
},
{
"no_policy_exists",
[]string{"not-a-real-policy"},
"no policy named",
2,
},
}
t.Run("validations", func(t *testing.T) {
@@ -69,7 +63,7 @@ func TestPolicyListCommand_Run(t *testing.T) {
}
})
t.Run("list", func(t *testing.T) {
t.Run("default", func(t *testing.T) {
t.Parallel()
client, closer := testVaultServer(t)
@@ -90,33 +84,6 @@ func TestPolicyListCommand_Run(t *testing.T) {
}
})
t.Run("read", func(t *testing.T) {
t.Parallel()
client, closer := testVaultServer(t)
defer closer()
policy := `path "secret/" {}`
if err := client.Sys().PutPolicy("my-policy", policy); err != nil {
t.Fatal(err)
}
ui, cmd := testPolicyListCommand(t)
cmd.client = client
code := cmd.Run([]string{
"my-policy",
})
if exp := 0; code != exp {
t.Errorf("expected %d to be %d", code, exp)
}
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
if !strings.Contains(combined, policy) {
t.Errorf("expected %q to contain %q", combined, policy)
}
})
t.Run("communication_failure", func(t *testing.T) {
t.Parallel()