Add response wrapping to list operations (#1814)

This commit is contained in:
Jeff Mitchell
2016-09-02 01:13:14 -04:00
committed by GitHub
parent 30e199cccf
commit 75f792b27e
6 changed files with 73 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package command
import (
"strings"
"testing"
"github.com/hashicorp/vault/http"
@@ -40,6 +41,9 @@ func TestUnwrap(t *testing.T) {
if method == "GET" && path == "secret/foo" {
return "60s"
}
if method == "LIST" && path == "secret" {
return "60s"
}
return ""
}
client.SetWrappingLookupFunc(wrapLookupFunc)
@@ -71,4 +75,33 @@ func TestUnwrap(t *testing.T) {
if output != "zap\n" {
t.Fatalf("unexpectd output:\n%s", output)
}
// Now test with list handling, specifically that it will be called with
// the list output formatter
ui.OutputWriter.Reset()
outer, err = client.Logical().List("secret")
if err != nil {
t.Fatalf("err: %s", err)
}
if outer == nil {
t.Fatal("outer response was nil")
}
if outer.WrapInfo == nil {
t.Fatal("outer wrapinfo was nil, response was %#v", *outer)
}
args = []string{
"-address", addr,
outer.WrapInfo.Token,
}
// Run the read
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
output = ui.OutputWriter.String()
if strings.TrimSpace(output) != "Keys\n----\nfoo" {
t.Fatalf("unexpected output:\n%s", output)
}
}