This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
model_ids_test.go
77 lines (64 loc) · 1.55 KB
/
model_ids_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
package bux
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestIDs_GormDataType will test the method GormDataType()
func TestIDs_GormDataType(t *testing.T) {
t.Parallel()
i := new(IDs)
assert.Equal(t, gormTypeText, i.GormDataType())
}
// TestIDs_Scan will test the method Scan()
func TestIDs_Scan(t *testing.T) {
t.Parallel()
t.Run("nil value", func(t *testing.T) {
i := IDs{}
err := i.Scan(nil)
require.NoError(t, err)
assert.Equal(t, 0, len(i))
})
t.Run("empty string", func(t *testing.T) {
i := IDs{}
err := i.Scan("\"\"")
assert.Error(t, err)
assert.Equal(t, 0, len(i))
})
t.Run("valid slice of ids", func(t *testing.T) {
i := IDs{}
err := i.Scan("[\"test1\",\"test2\"]")
require.NoError(t, err)
assert.Equal(t, 2, len(i))
assert.Equal(t, "test1", i[0])
assert.Equal(t, "test2", i[1])
})
t.Run("empty id slice", func(t *testing.T) {
i := IDs{}
err := i.Scan("[\"\"]")
require.NoError(t, err)
assert.Equal(t, 1, len(i))
assert.Equal(t, "", i[0])
})
t.Run("invalid JSON", func(t *testing.T) {
i := IDs{}
err := i.Scan("[test1]")
assert.Error(t, err)
})
}
// TestIDs_Value will test the method Value()
func TestIDs_Value(t *testing.T) {
t.Parallel()
t.Run("empty object", func(t *testing.T) {
i := IDs{}
value, err := i.Value()
require.NoError(t, err)
assert.Equal(t, "[]", value)
})
t.Run("ids present", func(t *testing.T) {
i := IDs{"test1"}
value, err := i.Value()
require.NoError(t, err)
assert.Equal(t, "[\"test1\"]", value)
})
}