open-vault/api/secret_test.go
2016-05-07 21:08:13 -04:00

51 lines
763 B
Go

package api
import (
"reflect"
"strings"
"testing"
)
func TestParseSecret(t *testing.T) {
raw := strings.TrimSpace(`
{
"lease_id": "foo",
"renewable": true,
"lease_duration": 10,
"data": {
"key": "value"
},
"warnings": [
"a warning!"
],
"wrap_info": {
"token": "token",
"ttl": 60
}
}`)
secret, err := ParseSecret(strings.NewReader(raw))
if err != nil {
t.Fatalf("err: %s", err)
}
expected := &Secret{
LeaseID: "foo",
Renewable: true,
LeaseDuration: 10,
Data: map[string]interface{}{
"key": "value",
},
Warnings: []string{
"a warning!",
},
WrapInfo: &SecretWrapInfo{
Token: "token",
TTL: 60,
},
}
if !reflect.DeepEqual(secret, expected) {
t.Fatalf("bad: %#v %#v", secret, expected)
}
}