-
Notifications
You must be signed in to change notification settings - Fork 3
/
vault_test.go
59 lines (48 loc) · 1.15 KB
/
vault_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 godoauth
import (
"bytes"
"reflect"
"testing"
)
var vaultReturnV_1 = `
{
"lease_id":"registry/foo/ed5d260f-8461-1c32-70af-04fac57c56fe",
"renewable":false,
"lease_duration":2592000,
"data":{
"access":"repository:foo/bar:*",
"password":"bar"
},
"auth":null
}
`
var vaultInvalidReturnV_1 = `
{
"lease_id":"registry/foo/ed5d260f-8461-1c32-70af-04fac57c56fe",
"renewable":false,
"lease_duration":2592000,
"data":{
"access":"foo/bar:*",
"password":"bar"
},
"auth":null
}
`
func TestUnmarshalText(t *testing.T) {
v := &VaultClient{}
access := make(map[string]Priv)
access["foo/bar"] = PrivAll
r, err := v.UnmarshalText(bytes.NewBuffer([]byte(vaultReturnV_1)))
if err != nil {
t.Errorf("unexpected error %s", err)
}
if r.Password != "bar" {
t.Errorf("Expected password bar, but received %s", r.Password)
}
if !reflect.DeepEqual(r.Access, access) {
t.Errorf("Expected same value between %v and %v", r.Access, access)
}
if _, err := v.UnmarshalText(bytes.NewBuffer([]byte(vaultInvalidReturnV_1))); err == nil {
t.Errorf("Expected error for %s", vaultInvalidReturnV_1)
}
}