package domain import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestGlobalID(t *testing.T) { t.Run("ToObjectReference", func(t *testing.T) { tt := []struct { input string id string oType string isValid bool }{ {"gid://app/Sparkle/1", "1", "sparkle", true}, {"gid://example/sparkle/1", "1", "sparkle", true}, {"gid://example/sparkle/696266fc-68df-11f0-bbc2-7ec11f4b308c", "696266fc-68df-11f0-bbc2-7ec11f4b308c", "sparkle", true}, {"gid://example/User/tanuki", "tanuki", "user", true}, {"", "", "", false}, {"gid://example", "", "", false}, {"gid://example/Example", "", "", false}, } for _, example := range tt { t.Run(example.input, func(t *testing.T) { reference := GlobalID(example.input).ToObjectReference() require.NotNil(t, reference) assert.Equal(t, example.id, reference.GetObjectId()) assert.Equal(t, example.oType, reference.GetObjectType()) if example.isValid { require.NoError(t, reference.Validate()) } else { require.Error(t, reference.Validate()) } }) } }) }