open-vault/api/secret_test.go

43 lines
644 B
Go
Raw Normal View History

2015-03-12 00:46:25 +00:00
package api
import (
"reflect"
"strings"
"testing"
)
func TestParseSecret(t *testing.T) {
raw := strings.TrimSpace(`
{
"lease_id": "foo",
2015-03-12 00:46:25 +00:00
"renewable": true,
"lease_duration": 10,
2015-03-16 20:29:51 +00:00
"data": {
"key": "value"
2015-10-07 21:21:41 +00:00
},
"warnings": [
"a warning!"
]
2015-03-12 00:46:25 +00:00
}`)
secret, err := ParseSecret(strings.NewReader(raw))
if err != nil {
t.Fatalf("err: %s", err)
}
expected := &Secret{
LeaseID: "foo",
2015-03-16 20:29:51 +00:00
Renewable: true,
LeaseDuration: 10,
2015-03-12 00:46:25 +00:00
Data: map[string]interface{}{
"key": "value",
},
2015-10-07 21:21:41 +00:00
Warnings: []string{
"a warning!",
},
2015-03-12 00:46:25 +00:00
}
if !reflect.DeepEqual(secret, expected) {
2015-03-16 20:29:51 +00:00
t.Fatalf("bad: %#v %#v", secret, expected)
2015-03-12 00:46:25 +00:00
}
}