github.com/nshntarora/pop@v0.1.2/slices_test.go (about) 1 package pop 2 3 import ( 4 "time" 5 6 "github.com/nshntarora/pop/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 UUID slices.UUID `db:"uuid_slice"` 15 Map slices.Map `db:"map"` 16 CreatedAt time.Time `json:"created_at" db:"created_at"` 17 UpdatedAt time.Time `json:"updated_at" db:"updated_at"` 18 } 19 20 func (s *PostgreSQLSuite) Test_String() { 21 transaction(func(tx *Connection) { 22 r := s.Require() 23 24 c := &Cake{ 25 String: slices.String{"a", "b", "c"}, 26 } 27 err := tx.Create(c) 28 r.NoError(err) 29 30 err = tx.Reload(c) 31 r.NoError(err) 32 r.Equal(slices.Int{}, c.Int) 33 r.Equal(slices.Float{}, c.Float) 34 r.Equal(slices.String{"a", "b", "c"}, c.String) 35 r.Equal(slices.UUID{}, c.UUID) 36 }) 37 } 38 39 func (s *PostgreSQLSuite) Test_Int() { 40 transaction(func(tx *Connection) { 41 r := s.Require() 42 43 c := &Cake{ 44 Int: slices.Int{1, 2, 3}, 45 } 46 err := tx.Create(c) 47 r.NoError(err) 48 49 err = tx.Reload(c) 50 r.NoError(err) 51 r.Equal(slices.Int{1, 2, 3}, c.Int) 52 r.Equal(slices.Float{}, c.Float) 53 r.Equal(slices.String{}, c.String) 54 r.Equal(slices.UUID{}, c.UUID) 55 }) 56 } 57 58 func (s *PostgreSQLSuite) Test_Float() { 59 transaction(func(tx *Connection) { 60 r := s.Require() 61 62 c := &Cake{ 63 Float: slices.Float{1.0, 2.1, 3.2}, 64 } 65 err := tx.Create(c) 66 r.NoError(err) 67 68 err = tx.Reload(c) 69 r.NoError(err) 70 r.Equal(slices.Int{}, c.Int) 71 r.Equal(slices.Float{1.0, 2.1, 3.2}, c.Float) 72 r.Equal(slices.String{}, c.String) 73 r.Equal(slices.UUID{}, c.UUID) 74 }) 75 }