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
|
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())
}
})
}
})
}
|