open-vault/command/capabilities_test.go

46 lines
1 KiB
Go
Raw Normal View History

2016-03-03 17:24:28 +00:00
package command
import (
"testing"
"github.com/hashicorp/vault/http"
2016-04-01 17:16:05 +00:00
"github.com/hashicorp/vault/meta"
2016-03-03 17:24:28 +00:00
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/cli"
)
2016-03-05 05:03:55 +00:00
func TestCapabilities_Basic(t *testing.T) {
core, _, token := vault.TestCoreUnsealed(t)
ln, addr := http.TestServer(t, core)
2016-03-03 17:24:28 +00:00
defer ln.Close()
ui := new(cli.MockUi)
c := &CapabilitiesCommand{
2016-04-01 17:16:05 +00:00
Meta: meta.Meta{
2016-03-05 05:03:55 +00:00
ClientToken: token,
Ui: ui,
2016-03-03 17:24:28 +00:00
},
}
2016-03-05 05:03:55 +00:00
var args []string
args = []string{"-address", addr}
2016-03-03 17:24:28 +00:00
if code := c.Run(args); code == 0 {
t.Fatalf("expected failure due to no args")
}
2016-03-05 05:03:55 +00:00
args = []string{"-address", addr, "testpath"}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
args = []string{"-address", addr, token, "test"}
if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}
args = []string{"-address", addr, "invalidtoken", "test"}
2016-03-03 19:00:36 +00:00
if code := c.Run(args); code == 0 {
t.Fatalf("expected failure due to invalid token")
2016-03-03 17:24:28 +00:00
}
}