Skip to content

Commit

Permalink
test for errors only
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerxxx committed Apr 17, 2023
1 parent b3f18e6 commit fcfa6a4
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions pkg/client/vault_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
package client

import (
"os"
vault "github.com/hashicorp/vault/api"
"testing"

vault "github.com/hashicorp/vault/api"
"github.com/stretchr/testify/assert"
)

func TestGetVaultClient(t *testing.T) {
// With sufficient configuration
os.Setenv("VAULT_ADDR", "http://localhost:8200")
os.Setenv("VAULT_TOKEN", "s.xxxxxx")
// TODO: login tests with mocked server

config := &AuthConfig{
AuthMethod: "token",
AuthMethod: "",
AuthPath: "",
AuthNoStore: true,
AuthMethodArgs: map[string]string{},
}

c, err := getVaultClient(config)
assert.Nil(t, err)
assert.IsType(t, &vault.Client{}, c)
assert.NotNil(t, c)

// Without VAULT_ADDR defined
os.Unsetenv("VAULT_ADDR")
c, err = getVaultClient(config)
assert.Error(t, err, "initializing vault client: VAULT_ADDR env is not defined")
assert.Error(t, err, "initializing vault client")
assert.IsType(t, &vault.Client{}, c)
assert.Nil(t, c)
}

0 comments on commit fcfa6a4

Please sign in to comment.