github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/queries/helpers_test.go (about) 1 package queries 2 3 import ( 4 "reflect" 5 "testing" 6 "time" 7 8 "github.com/volatiletech/null/v8" 9 ) 10 11 type testObj struct { 12 ID int 13 Name string `db:"TestHello"` 14 HeadSize int 15 } 16 17 func TestNonZeroDefaultSet(t *testing.T) { 18 t.Parallel() 19 20 type Anything struct { 21 ID int `boil:"id"` 22 Name string `boil:"name"` 23 CreatedAt *time.Time `boil:"created_at"` 24 UpdatedAt null.Time `boil:"updated_at"` 25 } 26 27 now := time.Now() 28 29 tests := []struct { 30 Defaults []string 31 Obj interface{} 32 Ret []string 33 }{ 34 { 35 []string{"id"}, 36 Anything{Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}}, 37 []string{}, 38 }, 39 { 40 []string{"id"}, 41 Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}}, 42 []string{"id"}, 43 }, 44 { 45 []string{}, 46 Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}}, 47 []string{}, 48 }, 49 { 50 []string{"id", "created_at", "updated_at"}, 51 Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}}, 52 []string{"id"}, 53 }, 54 { 55 []string{"id", "created_at", "updated_at"}, 56 Anything{ID: 5, Name: "hi", CreatedAt: &now, UpdatedAt: null.Time{Valid: true, Time: time.Now()}}, 57 []string{"id", "created_at", "updated_at"}, 58 }, 59 } 60 61 for i, test := range tests { 62 z := NonZeroDefaultSet(test.Defaults, test.Obj) 63 if !reflect.DeepEqual(test.Ret, z) { 64 t.Errorf("[%d] mismatch:\nWant: %#v\nGot: %#v", i, test.Ret, z) 65 } 66 } 67 }