-
Notifications
You must be signed in to change notification settings - Fork 1
/
vaults_test.go
101 lines (80 loc) · 2.31 KB
/
vaults_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package dvls
import (
"reflect"
"testing"
)
const testNewVaultId string = "eabd3646-acf8-44a4-9ba0-991df147c209"
var testNewVaultPassword string = "5w:mr6kPj"
var testVault Vault = Vault{
Name: "go-dvls tests",
Description: "Test Vault",
}
var testNewVault Vault = Vault{
ID: testNewVaultId,
Name: "go-dvls tests new",
Description: "Test",
}
func Test_Vaults(t *testing.T) {
testVault.ID = testVaultId
t.Run("GetVault", test_GetVault)
t.Run("NewVault", test_NewVault)
t.Run("UpdateVault", test_UpdateVault)
t.Run("DeleteVault", test_DeleteVault)
}
func test_GetVault(t *testing.T) {
vault, err := testClient.Vaults.Get(testVaultId)
if err != nil {
t.Fatal(err)
}
testVault.CreationDate = vault.CreationDate
testVault.ModifiedDate = vault.ModifiedDate
if !reflect.DeepEqual(testVault, vault) {
t.Fatalf("fetched vault did not match test vault. Expected %#v, got %#v", testVault, vault)
}
}
func test_NewVault(t *testing.T) {
err := testClient.Vaults.New(testNewVault, nil)
if err != nil {
t.Fatal(err)
}
vault, err := testClient.Vaults.Get(testNewVault.ID)
if err != nil {
t.Fatal(err)
}
vault.CreationDate = testNewVault.CreationDate
vault.ModifiedDate = testNewVault.ModifiedDate
if !reflect.DeepEqual(testNewVault, vault) {
t.Fatalf("fetched vault did not match test vault. Expected %#v, got %#v", testNewVault, vault)
}
}
func test_UpdateVault(t *testing.T) {
testNewVault.Name = "go-dvls tests new updated"
testNewVault.Description = "Test updated"
options := VaultOptions{Password: &testNewVaultPassword}
err := testClient.Vaults.Update(testNewVault, &options)
if err != nil {
t.Fatal(err)
}
valid, err := testClient.Vaults.ValidatePassword(testNewVault.ID, testNewVaultPassword)
if err != nil {
t.Fatal(err)
}
if !valid {
t.Fatal("vault password validation failed, expected ", testNewVaultPassword)
}
vault, err := testClient.Vaults.Get(testNewVault.ID)
if err != nil {
t.Fatal(err)
}
vault.CreationDate = testNewVault.CreationDate
vault.ModifiedDate = testNewVault.ModifiedDate
if !reflect.DeepEqual(testNewVault, vault) {
t.Fatalf("fetched vault did not match test vault. Expected %#v, got %#v", testNewVault, vault)
}
}
func test_DeleteVault(t *testing.T) {
err := testClient.Vaults.Delete(testNewVault.ID)
if err != nil {
t.Fatal(err)
}
}