-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsql_test.go
39 lines (33 loc) · 931 Bytes
/
sql_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
package typeid_test
import (
"testing"
"github.com/stretchr/testify/assert"
"go.jetify.com/typeid"
)
func TestScan(t *testing.T) {
testdata := []struct {
name string
input any
expected typeid.AnyID
}{
{"valid", "prefix_00041061050r3gg28a1c60t3gf", typeid.Must(typeid.FromString("prefix_00041061050r3gg28a1c60t3gf"))},
{"nil", nil, typeid.AnyID{}},
{"empty string", "", typeid.AnyID{}},
}
for _, td := range testdata {
t.Run(td.name, func(t *testing.T) {
var scanned typeid.AnyID
err := scanned.Scan(td.input)
assert.NoError(t, err)
assert.Equal(t, td.expected, scanned)
assert.Equal(t, td.expected.String(), scanned.String())
})
}
}
func TestValuer(t *testing.T) {
expected := "prefix_00041061050r3gg28a1c60t3gf"
tid := typeid.Must(typeid.FromString("prefix_00041061050r3gg28a1c60t3gf"))
actual, err := tid.Value()
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}