-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
slices_test.go
66 lines (54 loc) · 1.26 KB
/
slices_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
package pop
import (
"time"
"github.com/gobuffalo/pop/v6/slices"
)
type Cake struct {
ID int `db:"id"`
Int slices.Int `db:"int_slice"`
Float slices.Float `db:"float_slice"`
String slices.String `db:"string_slice"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
func (s *PostgreSQLSuite) Test_String() {
transaction(func(tx *Connection) {
r := s.Require()
c := &Cake{
String: slices.String{"a", "b", "c"},
}
err := tx.Create(c)
r.NoError(err)
err = tx.Reload(c)
r.NoError(err)
r.Equal(slices.String{"a", "b", "c"}, c.String)
})
}
func (s *PostgreSQLSuite) Test_Int() {
transaction(func(tx *Connection) {
r := s.Require()
c := &Cake{
Int: slices.Int{1, 2, 3},
}
err := tx.Create(c)
r.NoError(err)
err = tx.Reload(c)
r.NoError(err)
r.Equal(slices.Int{1, 2, 3}, c.Int)
r.Equal(slices.Float{}, c.Float)
})
}
func (s *PostgreSQLSuite) Test_Float() {
transaction(func(tx *Connection) {
r := s.Require()
c := &Cake{
Float: slices.Float{1.0, 2.1, 3.2},
}
err := tx.Create(c)
r.NoError(err)
err = tx.Reload(c)
r.NoError(err)
r.Equal(slices.Int{}, c.Int)
r.Equal(slices.Float{1.0, 2.1, 3.2}, c.Float)
})
}