-
Notifications
You must be signed in to change notification settings - Fork 1
/
uuid_array_test.go
51 lines (41 loc) · 1.28 KB
/
uuid_array_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
package uuid
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_StringArray_Scan(t *testing.T) {
var (
uuid1, _ = FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
uuid2, _ = FromString("3964fdbc-dc5a-4ec6-8a6b-eecfa5a8e9ae")
uuidArray = UUIDArray{uuid1, uuid2}
)
json := `["6ba7b810-9dad-11d1-80b4-00c04fd430c8","3964fdbc-dc5a-4ec6-8a6b-eecfa5a8e9ae"]`
newArrays := UUIDArray{}
err := newArrays.Scan(json)
assert.Equal(t, uuidArray, newArrays)
assert.NoError(t, err)
newArrays = UUIDArray{}
err = newArrays.Scan([]byte(json))
assert.Equal(t, uuidArray, newArrays)
assert.NoError(t, err)
err = newArrays.Scan(nil)
assert.Equal(t, newArrays, UUIDArray{})
assert.NoError(t, err)
err = newArrays.Scan(42)
assert.Error(t, err)
err = newArrays.Scan("{I am not a valid json")
assert.Error(t, err)
err = newArrays.Scan(nil)
assert.NoError(t, err)
}
func Test_StringArray_Value(t *testing.T) {
var (
uuid1, _ = FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
uuid2, _ = FromString("3964fdbc-dc5a-4ec6-8a6b-eecfa5a8e9ae")
uuidArray = UUIDArray{uuid1, uuid2}
)
expected := `["6ba7b810-9dad-11d1-80b4-00c04fd430c8","3964fdbc-dc5a-4ec6-8a6b-eecfa5a8e9ae"]`
val, _ := uuidArray.Value()
assert.Equal(t, expected, fmt.Sprintf("%s", val))
}