-
Notifications
You must be signed in to change notification settings - Fork 17
/
row_test.go
49 lines (41 loc) · 1.41 KB
/
row_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
package crud_test
import (
"testing"
"github.com/azer/crud/v2"
"github.com/stretchr/testify/assert"
)
func TestGettingRowValues(t *testing.T) {
rows, err := crud.GetRowValuesOf(UserProfile{})
assert.Nil(t, err)
assert.Equal(t, len(rows), 5)
rows, err = crud.GetRowValuesOf(UserProfile{
Name: "Azer",
Email: "azer@roadbeats.com",
Modified: 9223372036854775807,
Attachment: []byte("{ \"test\": true }"),
})
assert.Nil(t, err)
assert.Equal(t, len(rows), 5)
assert.Equal(t, rows[0].SQLColumn, "name")
assert.Equal(t, rows[0].Value.(string), "Azer")
assert.Equal(t, rows[1].SQLColumn, "bio")
assert.Equal(t, rows[1].Value.(string), "")
assert.Equal(t, rows[2].SQLColumn, "email")
assert.Equal(t, rows[2].Value.(string), "azer@roadbeats.com")
assert.Equal(t, rows[3].SQLColumn, "attachment")
assert.Equal(t, string(rows[3].Value.([]byte)), "{ \"test\": true }")
assert.Equal(t, rows[4].SQLColumn, "modified_col")
assert.Equal(t, rows[4].Value.(int64), int64(9223372036854775807))
rows, err = crud.GetRowValuesOf(Post{})
assert.Nil(t, err)
assert.Equal(t, len(rows), 3)
rows, err = crud.GetRowValuesOf(Post{
Title: "Hello World",
Text: "It's still 2015 here",
})
assert.Nil(t, err)
assert.Equal(t, rows[0].SQLColumn, "title")
assert.Equal(t, rows[0].Value.(string), "Hello World")
assert.Equal(t, rows[1].SQLColumn, "text")
assert.Equal(t, rows[1].Value.(string), "It's still 2015 here")
}