forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsql_builder_test.go
More file actions
74 lines (69 loc) · 1.29 KB
/
sql_builder_test.go
File metadata and controls
74 lines (69 loc) · 1.29 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package pop
import (
"testing"
"github.com/stretchr/testify/assert"
)
type v struct{}
type vv []v
type vptr *v
type vvptr []*v
func TestCacheKey(t *testing.T) {
tests := []struct {
name string
val any
want string
wantOK bool
}{{
name: "struct value",
val: v{},
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "struct pointer",
val: &v{},
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "vptr",
val: vptr(nil),
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "slice of struct values",
val: vv{},
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "slice of struct pointers",
val: vvptr{},
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "slice of struct pointer nil",
val: vvptr{nil},
want: "github.com/ory/pop/v6.v",
wantOK: true,
}, {
name: "string",
val: "hello",
}, {
name: "nil",
val: nil,
}, {
name: "int",
val: 42,
}, {
name: "int pointer",
val: func() *int { i := 42; return &i }(),
}, {
name: "map",
val: map[string]int{"a": 1},
}}
for _, tc := range tests {
t.Run("case="+tc.name, func(t *testing.T) {
got, ok := cacheKey(tc.val)
assert.Equal(t, tc.wantOK, ok)
assert.Equal(t, tc.want, got)
})
}
}