-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathsql_test.go
More file actions
45 lines (37 loc) · 1.1 KB
/
sql_test.go
File metadata and controls
45 lines (37 loc) · 1.1 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
package typeid_test
import (
"testing"
"github.com/stretchr/testify/assert"
"go.jetify.com/typeid"
)
func TestScan(t *testing.T) {
t.Parallel()
testdata := []struct {
name string
input any
expected typeid.AnyID
}{
{"valid_text", "prefix_01jtvs4hppfp8azhhy9x703dc1", typeid.Must(typeid.FromString("prefix_01jtvs4hppfp8azhhy9x703dc1"))},
{"valid_tuple", []byte("(prefix,0196b792-46d6-7d90-afc6-3e4f4e01b581)"), typeid.Must(typeid.FromString("prefix_01jtvs4hppfp8azhhy9x703dc1"))},
{"nil", nil, typeid.AnyID{}},
{"empty string", "", typeid.AnyID{}},
}
for _, td := range testdata {
t.Run(td.name, func(t *testing.T) {
t.Parallel()
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) {
t.Parallel()
expected := "prefix_01jtvs4hppfp8azhhy9x703dc1"
tid := typeid.Must(typeid.FromString("prefix_01jtvs4hppfp8azhhy9x703dc1"))
actual, err := tid.Value()
assert.NoError(t, err)
assert.Equal(t, expected, actual)
}