main
1package gid
2
3import (
4 "testing"
5
6 "github.com/cedar-policy/cedar-go"
7 "github.com/stretchr/testify/assert"
8)
9
10func TestNewEntityUID(t *testing.T) {
11 t.Run("returns an Entity UID with an integer id", func(t *testing.T) {
12 result := NewEntityUID("gid://example/User/1")
13
14 assert.Equal(t, cedar.EntityType("User"), result.Type)
15 assert.Equal(t, cedar.String("1"), result.ID)
16 })
17
18 t.Run("returns an Entity UID with a UUID", func(t *testing.T) {
19 result := NewEntityUID("gid://example/User/4707ce42-1017-11f0-acdf-7ec11f4b308c")
20
21 assert.Equal(t, cedar.EntityType("User"), result.Type)
22 assert.Equal(t, cedar.String("4707ce42-1017-11f0-acdf-7ec11f4b308c"), result.ID)
23 })
24
25 t.Run("returns an Entity UID with a namespace", func(t *testing.T) {
26 result := NewEntityUID("gid://example/Authn::User/1")
27
28 assert.Equal(t, cedar.EntityType("Authn::User"), result.Type)
29 assert.Equal(t, cedar.String("1"), result.ID)
30 })
31
32 t.Run("returns a default when a global id is not provided", func(t *testing.T) {
33 result := NewEntityUID("alice")
34
35 assert.Equal(t, cedar.EntityType("User"), result.Type)
36 assert.Equal(t, cedar.String("alice"), result.ID)
37 })
38}