-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_test.go
80 lines (74 loc) · 1.66 KB
/
lib_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
package surrealhigh
import (
"strings"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestId_Thing(t *testing.T) {
t.Run("null id", func(t *testing.T) {
id := Id(uuid.Nil)
table := Table("test")
assert.Equal(t, Thing("test:00000000_0000_0000_0000_000000000000"), id.Thing(table))
})
}
func TestThing_String(t *testing.T) {
assert.Equal(t, "test", Thing("test").String())
}
func TestNewID(t *testing.T) {
id := NewID()
assert.Equal(t, strings.ReplaceAll(uuid.UUID(id).String(), "-", "_"), id.String())
}
func TestNewIDFromThing(t *testing.T) {
for _, test := range []struct {
v Id
err error
errContains string
name string
th Thing
tb Table
}{
{
v: Id(uuid.Nil),
name: "match",
th: "test:00000000_0000_0000_0000_000000000000",
tb: "test",
},
{
err: ErrNotInThisTable,
name: "not this table",
th: "test:00000000_0000_0000_0000_000000000000",
tb: "taste",
},
{
err: ErrBadThing,
name: "thing colon missing",
th: "test00000000_0000_0000_0000_000000000000",
tb: "test",
},
{
errContains: "",
name: "thing colon missing",
th: "test00000000_0000_0000_0000_000000000000",
tb: "test",
},
} {
assert := assert.New(t)
t.Run(test.name, func(t *testing.T) {
id, err := NewIDFromThing(test.th, test.tb)
if test.err != nil {
assert.ErrorIs(err, test.err)
return
}
if test.errContains != "" {
assert.ErrorContains(err, test.errContains)
return
}
if err != nil && test.err != nil {
assert.NoError(err)
return
}
assert.Equal(test.v, id)
})
}
}