-
Notifications
You must be signed in to change notification settings - Fork 10
/
entity_uid_test.go
62 lines (51 loc) · 1.75 KB
/
entity_uid_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package types_test
import (
"testing"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
)
func TestEntity(t *testing.T) {
t.Parallel()
t.Run("Equal", func(t *testing.T) {
t.Parallel()
twoElems := types.EntityUID{"type", "id"}
twoElems2 := types.EntityUID{"type", "id"}
differentValues := types.EntityUID{"asdf", "vfds"}
testutil.FatalIf(t, !twoElems.Equal(twoElems), "%v not Equal to %v", twoElems, twoElems)
testutil.FatalIf(t, !twoElems.Equal(twoElems2), "%v not Equal to %v", twoElems, twoElems2)
testutil.FatalIf(t, twoElems.Equal(differentValues), "%v Equal to %v", twoElems, differentValues)
})
t.Run("string", func(t *testing.T) {
t.Parallel()
testutil.Equals(t, types.EntityUID{Type: "type", ID: "id"}.String(), `type::"id"`)
testutil.Equals(t, types.EntityUID{Type: "namespace::type", ID: "id"}.String(), `namespace::type::"id"`)
})
t.Run("MarshalCedar", func(t *testing.T) {
t.Parallel()
testutil.Equals(t, string(types.EntityUID{"type", "id"}.MarshalCedar()), `type::"id"`)
})
}
func TestEntityUIDSet(t *testing.T) {
t.Parallel()
t.Run("new empty set", func(t *testing.T) {
emptySets := []types.EntityUIDSet{
{},
types.NewEntityUIDSet(),
}
for _, es := range emptySets {
testutil.Equals(t, es.Len(), 0)
testutil.Equals(t, emptySets[0].Equal(es), true)
testutil.Equals(t, es.Equal(emptySets[0]), true)
}
})
t.Run("new set", func(t *testing.T) {
a := types.NewEntityUID("typeA", "1")
b := types.NewEntityUID("typeB", "2")
o := types.NewEntityUID("typeO", "2")
s := types.NewEntityUIDSet(a, b, o)
testutil.Equals(t, s.Len(), 3)
testutil.Equals(t, s.Contains(a), true)
testutil.Equals(t, s.Contains(b), true)
testutil.Equals(t, s.Contains(o), true)
})
}