github.com/RevenueMonster/sqlike@v1.0.6/plugin/opentracing/helper_test.go (about) 1 package opentracing 2 3 import ( 4 "bytes" 5 "database/sql/driver" 6 "testing" 7 "time" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestMapQuery(t *testing.T) { 13 var query string 14 15 query = `select * from "Table" where cond = "";` 16 w := new(bytes.Buffer) 17 mapQuery(query, w, nil) 18 require.Equal(t, `select * from "Table" where cond = "";`, w.String()) 19 20 w.Reset() 21 query = `select * from "Table" where cond = ? and bool = $2;` 22 mapQuery(query, w, []driver.NamedValue{{Value: "testing"}, {Value: true}}) 23 require.Equal(t, `select * from "Table" where cond = "testing" and bool = true;`, w.String()) 24 25 w.Reset() 26 query = `select * from "Table" where cond = ? and bool = $2 and name = :named;` 27 mapQuery(query, w, []driver.NamedValue{{Value: "testing"}}) 28 require.Equal(t, `select * from "Table" where cond = "testing" and bool = $2 and name = :named;`, w.String()) 29 30 w.Reset() 31 query = `select * from "Table" where cond = ? or f = ? and bool = ? and name = ?;` 32 mapQuery(query, w, []driver.NamedValue{{Value: "testing"}, {Value: float64(1033.2888)}, {Value: false}, {Value: `"testing"`}}) 33 require.Equal(t, `select * from "Table" where cond = "testing" or f = 1.0332888e+03 and bool = false and name = "\"testing\"";`, w.String()) 34 35 w.Reset() 36 ts, _ := time.Parse("2006-01-02", "2020-01-02") 37 query = `select * from "Table" where cond = ? and int = ? and uint64 = ? or f = ? and bool = ? and nil = ? and ts = ?;` 38 mapQuery(query, w, []driver.NamedValue{{Value: "testing"}, {Value: int64(1831923123)}, {Value: uint64(1831923123)}, {Value: float64(1033.2888)}, {Value: false}, {Value: nil}, {Value: ts}}) 39 require.Equal(t, `select * from "Table" where cond = "testing" and int = 1831923123 and uint64 = 1831923123 or f = 1.0332888e+03 and bool = false and nil = NULL and ts = "2020-01-02T00:00:00Z";`, w.String()) 40 }