command/write: test output

This commit is contained in:
Armon Dadgar 2015-04-27 15:08:03 -07:00
parent 43083225d0
commit 3b0c993909
1 changed files with 27 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"io"
"io/ioutil"
"os"
"strings"
"testing"
"github.com/hashicorp/vault/http"
@ -219,3 +220,29 @@ func TestWrite_fileValue(t *testing.T) {
t.Fatalf("bad: %#v", resp)
}
}
func TestWrite_Output(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := http.TestServer(t, core)
defer ln.Close()
ui := new(cli.MockUi)
c := &WriteCommand{
Meta: Meta{
ClientToken: token,
Ui: ui,
},
}
args := []string{
"-address", addr,
"auth/token/create",
"display_name=foo",
}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
if !strings.Contains(string(ui.OutputWriter.Bytes()), "Key") {
t.Fatalf("bad: %s", string(ui.OutputWriter.Bytes()))
}
}