Cloudeploy/consul-template/dependency/vault_token_test.go

34 lines
663 B
Go
Raw Normal View History

2020-10-09 14:04:29 +08:00
package dependency
import (
"testing"
"github.com/hashicorp/vault/api"
)
func TestVaultTokenFetch(t *testing.T) {
clients, server := testVaultServer(t)
defer server.Stop()
// Create a new token - the default token is a root token and is therefore
// not renewable
secret, err := clients.vault.Auth().Token().Create(&api.TokenCreateRequest{
Lease: "1h",
})
if err != nil {
t.Fatal(err)
}
clients.vault.SetToken(secret.Auth.ClientToken)
dep := new(VaultToken)
results, _, err := dep.Fetch(clients, nil)
if err != nil {
t.Fatal(err)
}
_, ok := results.(*Secret)
if !ok {
t.Fatal("could not convert result to a *vault/api.Secret")
}
}