mirror of https://github.com/status-im/consul.git
53 lines
694 B
Go
53 lines
694 B
Go
|
package acl
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestParse(t *testing.T) {
|
||
|
inp := `
|
||
|
key "" {
|
||
|
policy = "read"
|
||
|
}
|
||
|
key "foo/" {
|
||
|
policy = "write"
|
||
|
}
|
||
|
key "foo/bar/" {
|
||
|
policy = "read"
|
||
|
}
|
||
|
key "foo/bar/baz" {
|
||
|
polizy = "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", out)
|
||
|
}
|
||
|
}
|