2015-03-12 00:46:25 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseSecret(t *testing.T) {
|
|
|
|
raw := strings.TrimSpace(`
|
|
|
|
{
|
2015-04-08 20:35:32 +00:00
|
|
|
"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{
|
2015-04-08 20:35:32 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|