github.com/Accefy/pop@v0.0.0-20230428174248-e9f677eab5b9/slices_test.go (about) 1 package pop 2 3 import ( 4 "time" 5 6 "github.com/gobuffalo/pop/v6/slices" 7 ) 8 9 type Cake struct { 10 ID int `db:"id"` 11 Int slices.Int `db:"int_slice"` 12 Float slices.Float `db:"float_slice"` 13 String slices.String `db:"string_slice"` 14 CreatedAt time.Time `json:"created_at" db:"created_at"` 15 UpdatedAt time.Time `json:"updated_at" db:"updated_at"` 16 } 17 18 func (s *PostgreSQLSuite) Test_String() { 19 transaction(func(tx *Connection) { 20 r := s.Require() 21 22 c := &Cake{ 23 String: slices.String{"a", "b", "c"}, 24 } 25 err := tx.Create(c) 26 r.NoError(err) 27 28 err = tx.Reload(c) 29 r.NoError(err) 30 r.Equal(slices.String{"a", "b", "c"}, c.String) 31 }) 32 } 33 34 func (s *PostgreSQLSuite) Test_Int() { 35 transaction(func(tx *Connection) { 36 r := s.Require() 37 38 c := &Cake{ 39 Int: slices.Int{1, 2, 3}, 40 } 41 err := tx.Create(c) 42 r.NoError(err) 43 44 err = tx.Reload(c) 45 r.NoError(err) 46 r.Equal(slices.Int{1, 2, 3}, c.Int) 47 r.Equal(slices.Float{}, c.Float) 48 }) 49 } 50 51 func (s *PostgreSQLSuite) Test_Float() { 52 transaction(func(tx *Connection) { 53 r := s.Require() 54 55 c := &Cake{ 56 Float: slices.Float{1.0, 2.1, 3.2}, 57 } 58 err := tx.Create(c) 59 r.NoError(err) 60 61 err = tx.Reload(c) 62 r.NoError(err) 63 r.Equal(slices.Int{}, c.Int) 64 r.Equal(slices.Float{1.0, 2.1, 3.2}, c.Float) 65 }) 66 }