Skip to content

Commit

Permalink
types: fixup and test tag JSON marshalling
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Dowair <[email protected]>
  • Loading branch information
adowair committed Dec 5, 2024
1 parent 22b2bd0 commit 53ef8c6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions types/entity_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestEntitiesJSON(t *testing.T) {
t,
e,
`[
{"uid": {"type": "Type", "id": "id"}, "parents": [], "attrs": {"key": 42}},
{"uid": {"type": "Type" ,"id" :"id2"}, "parents": [{"type":"Type","id":"id"}], "attrs": {"key": 42}}
{"uid": {"type": "Type", "id": "id"}, "parents": [], "attrs": {"key": 42}, "tags": {}},
{"uid": {"type": "Type" ,"id" :"id2"}, "parents": [{"type":"Type","id":"id"}], "attrs": {"key": 42}, "tags":{}}
]`)
})

Expand Down
46 changes: 46 additions & 0 deletions types/entity_tag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package types_test

import (
"testing"
"time"

"github.com/cedar-policy/cedar-go"
"github.com/cedar-policy/cedar-go/internal/testutil"
"github.com/cedar-policy/cedar-go/types"
)

func TestEntityTagMarshalJSON(t *testing.T) {
t.Parallel()
e := types.Entity{
UID: types.NewEntityUID("FooType", "1"),
Parents: types.NewEntityUIDSet(),
Attributes: types.Record{},
Tags: cedar.NewRecord(types.RecordMap{
"key": types.String("value"),
"entity": types.NewEntityUID("FootType", "1"),
"datetime": types.NewDatetime(time.Unix(0, 0)),
}),
}

testutil.JSONMarshalsTo(t, e,
`{
"uid": {"type":"FooType","id":"1"},
"parents": [],
"attrs":{},
"tags": {
"datetime": {
"__extn": {
"fn": "datetime",
"arg": "1970-01-01T00:00:00.000Z"
}
},
"entity": {
"__entity": {
"type": "FootType",
"id": "1"
}
},
"key": "value"
}
}`)
}
4 changes: 3 additions & 1 deletion types/entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestEntityMarshalJSON(t *testing.T) {
types.NewEntityUID("QuuxType", "3"),
),
Attributes: types.Record{},
Tags: types.Record{},
}

testutil.JSONMarshalsTo(t, e,
Expand All @@ -52,6 +53,7 @@ func TestEntityMarshalJSON(t *testing.T) {
{"type":"QuuxType","id":"3"},
{"type":"QuuxType","id":"30"}
],
"attrs":{}
"attrs":{},
"tags":{}
}`)
}

0 comments on commit 53ef8c6

Please sign in to comment.