github.com/gogf/gf@v1.16.9/os/gtime/gtime_z_unit_sql_test.go (about) 1 package gtime_test 2 3 import ( 4 "github.com/gogf/gf/os/gtime" 5 "github.com/gogf/gf/test/gtest" 6 "testing" 7 ) 8 9 func TestTime_Scan(t1 *testing.T) { 10 gtest.C(t1, func(t *gtest.T) { 11 tt := gtime.Time{} 12 //test string 13 s := gtime.Now().String() 14 t.Assert(tt.Scan(s), nil) 15 t.Assert(tt.String(), s) 16 //test nano 17 n := gtime.TimestampNano() 18 t.Assert(tt.Scan(n), nil) 19 t.Assert(tt.TimestampNano(), n) 20 //test nil 21 none := (*gtime.Time)(nil) 22 t.Assert(none.Scan(nil), nil) 23 t.Assert(none, nil) 24 }) 25 26 } 27 28 func TestTime_Value(t1 *testing.T) { 29 gtest.C(t1, func(t *gtest.T) { 30 tt := gtime.Now() 31 s, err := tt.Value() 32 t.Assert(err, nil) 33 t.Assert(s, tt.Time) 34 //test nil 35 none := (*gtime.Time)(nil) 36 s, err = none.Value() 37 t.Assert(err, nil) 38 t.Assert(s, nil) 39 40 }) 41 }