mirror of https://github.com/status-im/consul.git
acl: Test parsing JSON
This commit is contained in:
parent
b802dd16eb
commit
05900f35c2
|
@ -50,3 +50,51 @@ key "foo/bar/baz" {
|
|||
t.Fatalf("bad: %#v %#v", out, exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParse_JSON(t *testing.T) {
|
||||
inp := `{
|
||||
"key": {
|
||||
"": {
|
||||
"policy": "read"
|
||||
},
|
||||
"foo/": {
|
||||
"policy": "write"
|
||||
},
|
||||
"foo/bar/": {
|
||||
"policy": "read"
|
||||
},
|
||||
"foo/bar/baz": {
|
||||
"policy": "deny"
|
||||
}
|
||||
}
|
||||
}`
|
||||
exp := &Policy{
|
||||
Keys: []*KeyPolicy{
|
||||
&KeyPolicy{
|
||||
Prefix: "",
|
||||
Policy: KeyPolicyRead,
|
||||
},
|
||||
&KeyPolicy{
|
||||
Prefix: "foo/",
|
||||
Policy: KeyPolicyWrite,
|
||||
},
|
||||
&KeyPolicy{
|
||||
Prefix: "foo/bar/",
|
||||
Policy: KeyPolicyRead,
|
||||
},
|
||||
&KeyPolicy{
|
||||
Prefix: "foo/bar/baz",
|
||||
Policy: KeyPolicyDeny,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
out, err := Parse(inp)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(out, exp) {
|
||||
t.Fatalf("bad: %#v %#v", out, exp)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue