-
Notifications
You must be signed in to change notification settings - Fork 10
/
authorize_test.go
46 lines (42 loc) · 1.03 KB
/
authorize_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package types
import (
"encoding/json"
"testing"
"github.com/cedar-policy/cedar-go/internal/testutil"
)
func TestJSONDecision(t *testing.T) {
t.Parallel()
t.Run("MarshalAllow", func(t *testing.T) {
t.Parallel()
d := Allow
b, err := d.MarshalJSON()
testutil.OK(t, err)
testutil.Equals(t, string(b), `"allow"`)
})
t.Run("MarshalDeny", func(t *testing.T) {
t.Parallel()
d := Deny
b, err := d.MarshalJSON()
testutil.OK(t, err)
testutil.Equals(t, string(b), `"deny"`)
})
t.Run("UnmarshalAllow", func(t *testing.T) {
t.Parallel()
var d Decision
err := json.Unmarshal([]byte(`"allow"`), &d)
testutil.OK(t, err)
testutil.Equals(t, d, Allow)
})
t.Run("UnmarshalDeny", func(t *testing.T) {
t.Parallel()
var d Decision
err := json.Unmarshal([]byte(`"deny"`), &d)
testutil.OK(t, err)
testutil.Equals(t, d, Deny)
})
}
func TestError(t *testing.T) {
t.Parallel()
e := DiagnosticError{PolicyID: "policy42", Message: "bad error"}
testutil.Equals(t, e.String(), "while evaluating policy `policy42`: bad error")
}