github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/sqlx/scanner/nullable/null_ignore_scanner_test.go (about) 1 package nullable_test 2 3 import ( 4 "testing" 5 6 . "github.com/onsi/gomega" 7 8 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/scanner/nullable" 9 ) 10 11 func BenchmarkNewNullIgnoreScanner(b *testing.B) { 12 v := 0 13 for i := 0; i < b.N; i++ { 14 _ = nullable.NewNullIgnoreScanner(&v).Scan(2) 15 } 16 b.Log(v) 17 } 18 19 func TestNullIgnoreScanner(t *testing.T) { 20 cases := []*struct { 21 name string 22 src interface{} 23 dst interface{} 24 }{ 25 {"ScanVal", int(1), 1}, 26 {"ScanNil", nil, 0}, 27 } 28 for _, c := range cases { 29 t.Run(c.name, func(t *testing.T) { 30 v := 0 31 _ = nullable.NewNullIgnoreScanner(&v).Scan(c.src) 32 NewWithT(t).Expect(v).To(Equal(c.dst)) 33 }) 34 } 35 }