-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvls_test.go
59 lines (48 loc) · 1005 Bytes
/
dvls_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package dvls
import (
"log"
"os"
"testing"
)
var (
testClient Client
testVaultId string
)
func TestMain(m *testing.M) {
testVaultId = os.Getenv("TEST_VAULT_ID")
err := setupTestClient()
if err != nil {
log.Fatal(err)
}
exitCode := m.Run()
os.Exit(exitCode)
}
func Test_Client(t *testing.T) {
t.Run("isLogged", test_isLogged)
}
func test_isLogged(t *testing.T) {
islogged, err := testClient.isLogged()
if err != nil {
t.Fatal(err)
}
if !islogged {
t.Fatalf("expected token to be valid but isLogged returned %t", islogged)
}
invalidClient := testClient
invalidClient.credential.token = "placeholder"
islogged, err = invalidClient.isLogged()
if err != nil {
t.Fatal(err)
}
if islogged {
t.Fatalf("expected token to be invalid but isLogged returned %t", islogged)
}
}
func setupTestClient() error {
c, err := NewClient(os.Getenv("TEST_USER"), os.Getenv("TEST_PASSWORD"), os.Getenv("TEST_INSTANCE"))
if err != nil {
return err
}
testClient = c
return nil
}