From 5b6530f382774091e38677787568856d546935d0 Mon Sep 17 00:00:00 2001 From: chenwenjie Date: Thu, 4 Feb 2021 10:16:22 +0800 Subject: [PATCH] u-update yaml package to v2.4.0 d-delete assert.go a-add testify replace assert.go --- assert.go | 50 ------------------------------------------- config_db_test.go | 41 ++++++++++++++++++----------------- config_mapper_test.go | 11 +++++----- expr_test.go | 9 ++++---- go.mod | 5 ++--- go.sum | 11 ++++++++++ params_test.go | 28 ++++++++++++------------ parser_xml_test.go | 2 +- proc_params_test.go | 34 ++++++++++++++--------------- sql_source_test.go | 17 ++++++++------- xmltag_test.go | 45 +++++++++++++++++++------------------- 11 files changed, 109 insertions(+), 144 deletions(-) delete mode 100644 assert.go diff --git a/assert.go b/assert.go deleted file mode 100644 index beaa919..0000000 --- a/assert.go +++ /dev/null @@ -1,50 +0,0 @@ -package gobatis - -import ( - "fmt" -) - -func assertEqual(a interface{}, b interface{}, message string) { - if a != b { - if message == "" { - message = fmt.Sprintf("%v != %v", a, b) - } - panic(message) - } -} - -func assertNotNil(a interface{}, message string) { - if nil == a { - if message == "" { - message = fmt.Sprintf("%v == nil", a) - } - panic(message) - } -} - -func assertNil(a interface{}, message string) { - if nil != a { - if message == "" { - message = fmt.Sprintf("%v != nil", a) - } - panic(message) - } -} - -func assertTrue(ok bool, message string) { - if !ok { - if message == "" { - message = fmt.Sprintf("ok == false") - } - panic(message) - } -} - -func assertNotTrue(ok bool, message string) { - if ok { - if message == "" { - message = fmt.Sprintf("ok == true") - } - panic(message) - } -} diff --git a/config_db_test.go b/config_db_test.go index e4d41df..bd18153 100644 --- a/config_db_test.go +++ b/config_db_test.go @@ -2,6 +2,7 @@ package gobatis import ( "fmt" + "github.com/stretchr/testify/assert" "testing" ) @@ -28,16 +29,16 @@ mappers: dbconf := buildDbConfig(ymlStr) dbc := dbconf.getDataSourceByName("ds1") - assertTrue(dbc != nil, "test fail: No datasource1") - assertTrue(dbconf.ShowSQL, "test fail: showSql == false") - assertEqual(dbc.DriverName, "mysql", "test fail, actual:"+dbc.DriverName) - assertEqual(dbc.DataSourceName, "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8", "test fail, actual:"+dbc.DataSourceName) - assertEqual(dbc.MaxLifeTime, 120, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxLifeTime)) - assertEqual(dbc.MaxOpenConns, 10, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxOpenConns)) - assertEqual(dbc.MaxIdleConns, 5, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxIdleConns)) - assertTrue(len(dbconf.Mappers) == 2, "len(dbconf.Mappers) != 2") - assertEqual(dbconf.Mappers[0], "userMapper.xml", "test fail, actual:"+dbconf.Mappers[0]) - assertEqual(dbconf.Mappers[1], "orderMapper.xml", "test fail, actual:"+dbconf.Mappers[1]) + assert.True(t, dbc != nil, "test fail: No datasource1") + assert.True(t, dbconf.ShowSQL, "test fail: showSql == false") + assert.Equal(t, dbc.DriverName, "mysql", "test fail, actual:"+dbc.DriverName) + assert.Equal(t, dbc.DataSourceName, "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8", "test fail, actual:"+dbc.DataSourceName) + assert.Equal(t, dbc.MaxLifeTime, 120, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxLifeTime)) + assert.Equal(t, dbc.MaxOpenConns, 10, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxOpenConns)) + assert.Equal(t, dbc.MaxIdleConns, 5, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxIdleConns)) + assert.True(t, len(dbconf.Mappers) == 2, "len(dbconf.Mappers) != 2") + assert.Equal(t, dbconf.Mappers[0], "userMapper.xml", "test fail, actual:"+dbconf.Mappers[0]) + assert.Equal(t, dbconf.Mappers[1], "orderMapper.xml", "test fail, actual:"+dbconf.Mappers[1]) } func TestDbConfigCodeInit(t *testing.T) { @@ -57,14 +58,14 @@ func TestDbConfigCodeInit(t *testing.T) { Build() dbc := dbconf.getDataSourceByName("ds1") - assertTrue(dbc != nil, "test fail: No datasource1") - assertTrue(dbconf.ShowSQL, "test fail: showSql == false") - assertEqual(dbc.DriverName, "mysql", "test fail, actual:"+dbc.DriverName) - assertEqual(dbc.DataSourceName, "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8", "test fail, actual:"+dbc.DataSourceName) - assertEqual(dbc.MaxLifeTime, 120, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxLifeTime)) - assertEqual(dbc.MaxOpenConns, 10, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxOpenConns)) - assertEqual(dbc.MaxIdleConns, 5, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxIdleConns)) - assertTrue(len(dbconf.Mappers) == 2, "len(dbconf.Mappers) != 2") - assertEqual(dbconf.Mappers[0], "userMapper.xml", "test fail, actual:"+dbconf.Mappers[0]) - assertEqual(dbconf.Mappers[1], "orderMapper.xml", "test fail, actual:"+dbconf.Mappers[1]) + assert.True(t, dbc != nil, "test fail: No datasource1") + assert.True(t, dbconf.ShowSQL, "test fail: showSql == false") + assert.Equal(t, dbc.DriverName, "mysql", "test fail, actual:"+dbc.DriverName) + assert.Equal(t, dbc.DataSourceName, "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8", "test fail, actual:"+dbc.DataSourceName) + assert.Equal(t, dbc.MaxLifeTime, 120, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxLifeTime)) + assert.Equal(t, dbc.MaxOpenConns, 10, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxOpenConns)) + assert.Equal(t, dbc.MaxIdleConns, 5, "test fail, actual:"+fmt.Sprintf("%d", dbc.MaxIdleConns)) + assert.True(t, len(dbconf.Mappers) == 2, "len(dbconf.Mappers) != 2") + assert.Equal(t, dbconf.Mappers[0], "userMapper.xml", "test fail, actual:"+dbconf.Mappers[0]) + assert.Equal(t, dbconf.Mappers[1], "orderMapper.xml", "test fail, actual:"+dbconf.Mappers[1]) } diff --git a/config_mapper_test.go b/config_mapper_test.go index 2c63a4e..3000e75 100644 --- a/config_mapper_test.go +++ b/config_mapper_test.go @@ -1,6 +1,7 @@ package gobatis import ( + "github.com/stretchr/testify/assert" "strings" "testing" ) @@ -38,9 +39,9 @@ func TestBuildConfig(t *testing.T) { ` r := strings.NewReader(xmlStr) conf := buildMapperConfig(r) - assertNotNil(conf.getMappedStmt("Mapper.findMapById"), "Mapper.findMapById mapped stmt is nil") - assertNotNil(conf.getMappedStmt("Mapper.insertStructsBatch"), "Mapper.insertStructsBatch mapped stmt is nil") - assertNotNil(conf.getMappedStmt("Mapper.updateByStruct"), "Mapper.updateByStruct mapped stmt is nil") - assertNotNil(conf.getMappedStmt("Mapper.deleteById"), "Mapper.deleteById mapped stmt is nil") - assertNotNil(conf.getMappedStmt("Mapper.updateByCond"), "Mapper.deleteById mapped stmt is nil") + assert.NotNil(t, conf.getMappedStmt("Mapper.findMapById"), "Mapper.findMapById mapped stmt is nil") + assert.NotNil(t, conf.getMappedStmt("Mapper.insertStructsBatch"), "Mapper.insertStructsBatch mapped stmt is nil") + assert.NotNil(t, conf.getMappedStmt("Mapper.updateByStruct"), "Mapper.updateByStruct mapped stmt is nil") + assert.NotNil(t, conf.getMappedStmt("Mapper.deleteById"), "Mapper.deleteById mapped stmt is nil") + assert.NotNil(t, conf.getMappedStmt("Mapper.updateByCond"), "Mapper.deleteById mapped stmt is nil") } diff --git a/expr_test.go b/expr_test.go index 228436c..b7dbdf1 100644 --- a/expr_test.go +++ b/expr_test.go @@ -2,6 +2,7 @@ package gobatis import ( "fmt" + "github.com/stretchr/testify/assert" "testing" ) @@ -48,15 +49,15 @@ func TestExpr_eval(t *testing.T) { for i, ex := range expression { ok := eval(ex, params) fmt.Printf("Index:%v Expr:%v >>>> Result:%v \n", i, ex, ok) - assertExpr(i, ok, ex) + assertExpr(t, i, ok, ex) } } -func assertExpr(i int, ok bool, expr string) { +func assertExpr(t *testing.T, i int, ok bool, expr string) { switch i { case 0, 3, 4, 6, 8, 9, 12, 14, 17, 22: // false - assertNotTrue(ok, "Expr:"+expr+" Result:true") + assert.True(t, !ok, "Expr:"+expr+" Result:true") case 1, 2, 5, 7, 10, 11, 13, 15, 16, 18, 19, 20, 21: // true - assertTrue(ok, "Expr:"+expr+" Result:false") + assert.True(t, ok, "Expr:"+expr+" Result:false") } } diff --git a/go.mod b/go.mod index 899c569..9b21f54 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.12 require ( github.com/antonmedv/expr v1.1.4 github.com/go-sql-driver/mysql v1.4.1 - gopkg.in/yaml.v2 v2.0.0-00010101000000-000000000000 + gopkg.in/yaml.v2 v2.4.0 + github.com/stretchr/testify v1.7.0 ) - -replace gopkg.in/yaml.v2 => github.com/go-yaml/yaml v2.1.0+incompatible diff --git a/go.sum b/go.sum index efb3c3e..25b74ef 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,17 @@ github.com/antonmedv/expr v1.1.4 h1:ReeidbMJQZsujmBaYdaCEtfAvSH5bd/HHApjhyorBlE= github.com/antonmedv/expr v1.1.4/go.mod h1:AdVomDZyjUit6l23+Owki7ZHDtvJDjsaP4YmqB44OJA= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/params_test.go b/params_test.go index 280f6e1..2f05886 100644 --- a/params_test.go +++ b/params_test.go @@ -1,47 +1,47 @@ package gobatis import ( + "github.com/stretchr/testify/assert" "reflect" "testing" ) type TestStruct struct { - } -func TestVal(t *testing.T) { +func TestVal(t *testing.T) { paramsInt := 1 v := reflect.ValueOf(paramsInt) - assertTrue(v.Kind() == reflect.Int, "test fail: params is not int") + assert.True(t, v.Kind() == reflect.Int, "test fail: params is not int") paramsInt64 := int64(1) v = reflect.ValueOf(paramsInt64) - assertTrue(v.Kind() == reflect.Int64, "test fail: params is not int64") + assert.True(t, v.Kind() == reflect.Int64, "test fail: params is not int64") paramsString := "" v = reflect.ValueOf(paramsString) - assertTrue(v.Kind() == reflect.String, "test fail: params is not string") + assert.True(t, v.Kind() == reflect.String, "test fail: params is not string") paramsSlice := []int{1, 2, 3} v = reflect.ValueOf(paramsSlice) - assertTrue(v.Kind() == reflect.Slice, "test fail: params is not slice") + assert.True(t, v.Kind() == reflect.Slice, "test fail: params is not slice") paramsStruct := TestStruct{} v = reflect.ValueOf(paramsStruct) - assertTrue(v.Kind() == reflect.Struct, "test fail: params is not struct") + assert.True(t, v.Kind() == reflect.Struct, "test fail: params is not struct") paramsPtr := &TestStruct{} v = reflect.ValueOf(paramsPtr) - assertTrue(v.Kind() == reflect.Ptr, "test fail: params is not ptr") + assert.True(t, v.Kind() == reflect.Ptr, "test fail: params is not ptr") v = v.Elem() - assertTrue(v.Kind() == reflect.Struct, "test fail: params is not struct") + assert.True(t, v.Kind() == reflect.Struct, "test fail: params is not struct") - paramsStructs := []*TestStruct{{},{},{}} + paramsStructs := []*TestStruct{{}, {}, {}} v = reflect.ValueOf(paramsStructs) - assertTrue(v.Kind() == reflect.Slice, "test fail: params is not slice") - assertTrue(v.Len() == 3, "test fail: params len != 3") + assert.True(t, v.Kind() == reflect.Slice, "test fail: params is not slice") + assert.True(t, v.Len() == 3, "test fail: params len != 3") v0 := v.Index(0) - assertTrue(v0.Kind() == reflect.Ptr, "test fail: ele is not ptr") + assert.True(t, v0.Kind() == reflect.Ptr, "test fail: ele is not ptr") v0 = v0.Elem() - assertTrue(v0.Kind() == reflect.Struct, "test fail: ele is not struct") + assert.True(t, v0.Kind() == reflect.Struct, "test fail: ele is not struct") } diff --git a/parser_xml_test.go b/parser_xml_test.go index 5decc3f..891466c 100644 --- a/parser_xml_test.go +++ b/parser_xml_test.go @@ -26,5 +26,5 @@ func TestXmlNode_parse(t *testing.T) { ` r := strings.NewReader(xmlStr) rn := parse(r) - assertNotNil(rn, "Parse xml result is nil") + assert.NotNil(t, rn, "Parse xml result is nil") } diff --git a/proc_params_test.go b/proc_params_test.go index 40733c6..53166fb 100644 --- a/proc_params_test.go +++ b/proc_params_test.go @@ -1,44 +1,44 @@ package gobatis import ( + "github.com/stretchr/testify/assert" "testing" "time" ) type TestStruct2 struct { - T NullTime - S NullString + T NullTime + S NullString Id int64 } -func TestParams(t *testing.T) { +func TestParams(t *testing.T) { paramB := "" res := paramProcess(paramB) - assertNotNil(res["0"], "test fail: res[0] == nil") - assertEqual(res["0"], "", "test fail: res[0] != ''") - + assert.NotNil(t, res["0"], "test fail: res[0] == nil") + assert.Equal(t, res["0"], "", "test fail: res[0] != ''") paramM := map[string]interface{}{ - "id": nil, - "name":"wenj91", + "id": nil, + "name": "wenj91", } res = paramProcess(paramM) - assertNil(res["id"], "test fail: res['id'] != nil") - assertNotNil(res["name"], "test fail: res['name'] == nil") - assertEqual(res["name"], "wenj91", "test fail: res['name'] != 'wenj91'") + assert.Nil(t, res["id"], "test fail: res['id'] != nil") + assert.NotNil(t, res["name"], "test fail: res['name'] == nil") + assert.Equal(t, res["name"], "wenj91", "test fail: res['name'] != 'wenj91'") paramNil := NullString{"str", true} res = paramProcess(paramNil) - assertNotNil(res["0"], "test fail: res['0'] == nil") - assertEqual(res["0"], "str", "test fail: res['0'] != 'str'") + assert.NotNil(t, res["0"], "test fail: res['0'] == nil") + assert.Equal(t, res["0"], "str", "test fail: res['0'] != 'str'") tt, _ := time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05") paramS := &TestStruct2{ T: NullTime{tt, true}, } res = paramProcess(paramS) - assertNotNil(res["T"], "test fail: res['T'] == nil") - assertEqual(res["T"], "2006-01-02 15:04:05", "test fail: res['T'] != '2006-01-02 15:04:05'") - assertNil(res["S"], "test fail: res['S'] != nil") - assertEqual(res["Id"], int64(0), "test fail: res['Id'] != 0") + assert.NotNil(t, res["T"], "test fail: res['T'] == nil") + assert.Equal(t, res["T"], "2006-01-02 15:04:05", "test fail: res['T'] != '2006-01-02 15:04:05'") + assert.Nil(t, res["S"], "test fail: res['S'] != nil") + assert.Equal(t, res["Id"], int64(0), "test fail: res['Id'] != 0") } diff --git a/sql_source_test.go b/sql_source_test.go index 9b70e31..0f297ac 100644 --- a/sql_source_test.go +++ b/sql_source_test.go @@ -2,6 +2,7 @@ package gobatis import ( "fmt" + "github.com/stretchr/testify/assert" "testing" ) @@ -17,9 +18,9 @@ func TestStaticSqlSource_getBoundSql(t *testing.T) { }) expc := "select * from t_gap where id = ? and gap = ?" - assertEqual(bs.sqlStr, expc, "test failed, actual:"+bs.sqlStr) - assertEqual(bs.params["id"], 1, "test failed, actual:"+fmt.Sprintf("%d", bs.params["id"])) - assertEqual(bs.params["gap"], 10, "test failed, actual:"+fmt.Sprintf("%d", bs.params["gap"])) + assert.Equal(t, bs.sqlStr, expc, "test failed, actual:"+bs.sqlStr) + assert.Equal(t, bs.params["id"], 1, "test failed, actual:"+fmt.Sprintf("%d", bs.params["id"])) + assert.Equal(t, bs.params["gap"], 10, "test failed, actual:"+fmt.Sprintf("%d", bs.params["gap"])) } func TestDynamicSqlSource_getBoundSql(t *testing.T) { @@ -94,9 +95,9 @@ func TestDynamicSqlSource_getBoundSql(t *testing.T) { bs := ds.getBoundSql(params) expc := "select 1 from t_gap where age = ? and name = ? and code = 'cctv' and id in ( ? , ? , ? )" - assertEqual(bs.sqlStr, expc, "test failed, actual:"+bs.sqlStr) - assertEqual(bs.params["name"], "Sean", "test failed, actual:"+fmt.Sprintf("%d", bs.params["id"])) - assertEqual(bs.extParams["_ls_item_p_item0.A"], "aa", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item0.A"])) - assertEqual(bs.extParams["_ls_item_p_item1.A"], "bb", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item1.A"])) - assertEqual(bs.extParams["_ls_item_p_item2.A"], "cc", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item2.A"])) + assert.Equal(t, bs.sqlStr, expc, "test failed, actual:"+bs.sqlStr) + assert.Equal(t, bs.params["name"], "Sean", "test failed, actual:"+fmt.Sprintf("%d", bs.params["id"])) + assert.Equal(t, bs.extParams["_ls_item_p_item0.A"], "aa", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item0.A"])) + assert.Equal(t, bs.extParams["_ls_item_p_item1.A"], "bb", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item1.A"])) + assert.Equal(t, bs.extParams["_ls_item_p_item2.A"], "cc", "test failed, actual:"+fmt.Sprintf("%s", bs.extParams["_ls_item_p_item2.A"])) } diff --git a/xmltag_test.go b/xmltag_test.go index a3070e9..85bbfee 100644 --- a/xmltag_test.go +++ b/xmltag_test.go @@ -2,6 +2,7 @@ package gobatis import ( "fmt" + "github.com/stretchr/testify/assert" "strings" "testing" ) @@ -24,7 +25,7 @@ func TestTextSqlNode_build(t *testing.T) { textSqlNode.build(ctx) expc := "select 1 from t_gap" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) } func TestIfSqlNode_True_build(t *testing.T) { @@ -44,7 +45,7 @@ func TestIfSqlNode_True_build(t *testing.T) { ifSqlNode.build(ctx) expc := "select 1 from t_gap" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) } func TestIfSqlNode_False_build(t *testing.T) { @@ -64,7 +65,7 @@ func TestIfSqlNode_False_build(t *testing.T) { ifSqlNode.build(ctx) expc := "" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) } func TestForeachSqlNode_build(t *testing.T) { @@ -90,10 +91,10 @@ func TestForeachSqlNode_build(t *testing.T) { f.build(ctx) expc := "select 1 from t_gap where id in ( #{_ls_item_p_item0} , #{_ls_item_p_item1} , #{_ls_item_p_item2} )" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["_ls_item_p_item0"], 1, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item0"])) - assertEqual(ctx.params["_ls_item_p_item1"], 2, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item1"])) - assertEqual(ctx.params["_ls_item_p_item2"], 3, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item2"])) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["_ls_item_p_item0"], 1, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item0"])) + assert.Equal(t, ctx.params["_ls_item_p_item1"], 2, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item1"])) + assert.Equal(t, ctx.params["_ls_item_p_item2"], 3, "test failed, actual:"+fmt.Sprintf("%d", ctx.params["_ls_item_p_item2"])) } func TestMixedSqlNode_build(t *testing.T) { @@ -143,10 +144,10 @@ func TestMixedSqlNode_build(t *testing.T) { mixedSqlNode.build(ctx) expc := "select 1 from t_gap where 1 = 1 and name = #{name} and id in ( #{_ls_item_p_item0.A} , #{_ls_item_p_item1.A} , #{_ls_item_p_item2.A} )" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["_ls_item_p_item0.A"], "aa", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item0.A"])) - assertEqual(ctx.params["_ls_item_p_item1.A"], "bb", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item1.A"])) - assertEqual(ctx.params["_ls_item_p_item2.A"], "cc", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item2.A"])) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["_ls_item_p_item0.A"], "aa", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item0.A"])) + assert.Equal(t, ctx.params["_ls_item_p_item1.A"], "bb", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item1.A"])) + assert.Equal(t, ctx.params["_ls_item_p_item2.A"], "cc", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["_ls_item_p_item2.A"])) } func TestSetSqlNode_build(t *testing.T) { @@ -177,9 +178,9 @@ func TestSetSqlNode_build(t *testing.T) { setSqlNode.build(ctx) expc := "set name = #{name} , name2 = #{name2}" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) - assertEqual(ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) + assert.Equal(t, ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) } func TestTrimSqlNode_build(t *testing.T) { @@ -212,9 +213,9 @@ func TestTrimSqlNode_build(t *testing.T) { trimSqlNode.build(ctx) expc := "name = #{name} and name2 = #{name2}" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) - assertEqual(ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) + assert.Equal(t, ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) } func TestWhereSqlNode_build(t *testing.T) { @@ -245,9 +246,9 @@ func TestWhereSqlNode_build(t *testing.T) { whereSqlNode.build(ctx) expc := "where name = #{name} and name2 = #{name2}" - assertEqual(ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) - assertEqual(ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) + assert.Equal(t, ctx.toSql(), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["name"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) + assert.Equal(t, ctx.params["name2"], "wenj91", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name2"])) } func TestChooseSqlNode_build(t *testing.T) { @@ -285,6 +286,6 @@ func TestChooseSqlNode_build(t *testing.T) { ctx := newDynamicContext(params) choose.build(ctx) expc := "and name = 'aa'" - assertEqual(strings.Trim(ctx.toSql(), " "), expc, "test failed, actual:"+ctx.toSql()) - assertEqual(ctx.params["name"], "aa", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) + assert.Equal(t, strings.Trim(ctx.toSql(), " "), expc, "test failed, actual:"+ctx.toSql()) + assert.Equal(t, ctx.params["name"], "aa", "test failed, actual:"+fmt.Sprintf("%s", ctx.params["name"])) }