MCPcopy
hub / github.com/ory/keto / TestUUIDMapping

Function TestUUIDMapping

internal/persistence/sql/uuid_mapping_test.go:36–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34}
35
36func TestUUIDMapping(t *testing.T) {
37 t.Parallel()
38
39 for _, dsn := range dbx.GetDSNs(t, false) {
40 dsn := dsn
41 t.Run("dsn="+dsn.Name, func(t *testing.T) {
42 t.Parallel()
43 reg := driver.NewTestRegistry(t, dsn)
44 c, err := reg.PopConnection(context.Background())
45 require.NoError(t, err)
46
47 testUUID := uuid.Must(uuid.NewV4())
48
49 for _, tc := range []struct {
50 desc string
51 mappings interface{}
52 assertErr assert.ErrorAssertionFunc
53 }{{
54 desc: "empty should not fail on constraint",
55 mappings: &sql.UUIDMapping{},
56 assertErr: assert.NoError,
57 }, {
58 desc: "empty strings should not fail on constraint",
59 mappings: &sql.UUIDMapping{ID: uuid.Nil},
60 assertErr: assert.NoError,
61 }, {
62 desc: "single with string rep should succeed",
63 mappings: &sql.UUIDMapping{StringRepresentation: "foo"},
64 assertErr: assert.NoError,
65 }, {
66 desc: "two with same uuid should fail on constraint",
67 mappings: &[]sql.UUIDMapping{
68 {ID: testUUID, StringRepresentation: "foo"},
69 {ID: testUUID, StringRepresentation: "bar"},
70 },
71 assertErr: assertCheckErr,
72 }, {
73 desc: "two with same rep should succeed",
74 mappings: &[]sql.UUIDMapping{
75 {ID: uuid.Must(uuid.NewV4()), StringRepresentation: "bar"},
76 {ID: uuid.Must(uuid.NewV4()), StringRepresentation: "bar"},
77 },
78 assertErr: assert.NoError,
79 }} {
80 tc := tc
81 t.Run("case="+tc.desc, func(t *testing.T) {
82 t.Parallel()
83 err := c.Create(tc.mappings)
84 tc.assertErr(t, err)
85 })
86 }
87 })
88 }
89}

Callers

nothing calls this directly

Calls 3

GetDSNsFunction · 0.92
NewTestRegistryFunction · 0.92
PopConnectionMethod · 0.65

Tested by

no test coverage detected