-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsq_test.go
103 lines (95 loc) · 2.57 KB
/
sq_test.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package sq
import (
"database/sql"
"testing"
"github.com/bokwoon95/sq/internal/testutil"
"github.com/google/uuid"
)
type Weekday uint
const (
WeekdayInvalid Weekday = iota
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
func (d Weekday) Enumerate() []string {
return []string{
WeekdayInvalid: "",
Sunday: "Sunday",
Monday: "Monday",
Tuesday: "Tuesday",
Wednesday: "Wednesday",
Thursday: "Thursday",
Friday: "Friday",
Saturday: "Saturday",
}
}
func Test_preprocessValue(t *testing.T) {
type TestTable struct {
description string
dialect string
input any
wantOutput any
}
tests := []TestTable{{
description: "empty",
input: nil,
wantOutput: nil,
}, {
description: "driver.Valuer",
input: uuid.MustParse("a4f952f1-4c45-4e63-bd4e-159ca33c8e20"),
wantOutput: "a4f952f1-4c45-4e63-bd4e-159ca33c8e20",
}, {
description: "Postgres DialectValuer",
dialect: DialectPostgres,
input: UUIDValue(uuid.MustParse("a4f952f1-4c45-4e63-bd4e-159ca33c8e20")),
wantOutput: "a4f952f1-4c45-4e63-bd4e-159ca33c8e20",
}, {
description: "MySQL DialectValuer",
dialect: DialectMySQL,
input: UUIDValue(uuid.MustParse("a4f952f1-4c45-4e63-bd4e-159ca33c8e20")),
wantOutput: []byte{0xa4, 0xf9, 0x52, 0xf1, 0x4c, 0x45, 0x4e, 0x63, 0xbd, 0x4e, 0x15, 0x9c, 0xa3, 0x3c, 0x8e, 0x20},
}, {
description: "Postgres [16]byte",
dialect: DialectPostgres,
input: [16]byte{0xa4, 0xf9, 0x52, 0xf1, 0x4c, 0x45, 0x4e, 0x63, 0xbd, 0x4e, 0x15, 0x9c, 0xa3, 0x3c, 0x8e, 0x20},
wantOutput: "a4f952f1-4c45-4e63-bd4e-159ca33c8e20",
}, {
description: "MySQL [16]byte",
dialect: DialectMySQL,
input: [16]byte{0xa4, 0xf9, 0x52, 0xf1, 0x4c, 0x45, 0x4e, 0x63, 0xbd, 0x4e, 0x15, 0x9c, 0xa3, 0x3c, 0x8e, 0x20},
wantOutput: []byte{0xa4, 0xf9, 0x52, 0xf1, 0x4c, 0x45, 0x4e, 0x63, 0xbd, 0x4e, 0x15, 0x9c, 0xa3, 0x3c, 0x8e, 0x20},
}, {
description: "Enumeration",
input: Monday,
wantOutput: "Monday",
}, {
description: "int",
input: 42,
wantOutput: 42,
}, {
description: "sql.NullString",
input: sql.NullString{
Valid: false,
String: "lorem ipsum dolor sit amet",
},
wantOutput: nil,
}}
for _, tt := range tests {
tt := tt
t.Run(tt.description, func(t *testing.T) {
t.Parallel()
gotOutput, err := preprocessValue(tt.dialect, tt.input)
if err != nil {
t.Fatal(testutil.Callers(), err)
}
if diff := testutil.Diff(gotOutput, tt.wantOutput); diff != "" {
t.Error(testutil.Callers(), diff)
}
})
}
}