Replace gotest.tools with github.com/stretchr/testify.

This commit is contained in:
go-jet 2020-02-11 10:25:13 +01:00
parent 3013dc3647
commit 3efbb0ccd9
34 changed files with 462 additions and 457 deletions

View file

@ -1,7 +1,7 @@
package snaker
import (
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
)

View file

@ -1,7 +1,7 @@
package jet
import (
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
)

View file

@ -2,7 +2,7 @@ package jet
import (
"github.com/google/uuid"
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
@ -30,7 +30,7 @@ func TestArgToString(t *testing.T) {
assert.Equal(t, argToString(uuid.MustParse("b68dbff4-a87d-11e9-a7f2-98ded00c39c6")), "'b68dbff4-a87d-11e9-a7f2-98ded00c39c6'")
time, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, argToString(time), "'2006-01-02 15:04:05-07:00'")
func() {

View file

@ -1,7 +1,7 @@
package jet
import (
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
)

View file

@ -1,7 +1,7 @@
package jet
import (
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
@ -56,8 +56,8 @@ func assertClauseSerialize(t *testing.T, clause Serializer, query string, args .
//fmt.Println(out.Buff.String())
assert.DeepEqual(t, out.Buff.String(), query)
assert.DeepEqual(t, out.Args, args)
assert.Equal(t, out.Buff.String(), query)
assert.Equal(t, out.Args, args)
}
func assertClauseSerializeErr(t *testing.T, clause Serializer, errString string) {
@ -76,14 +76,14 @@ func assertClauseDebugSerialize(t *testing.T, clause Serializer, query string, a
//fmt.Println(out.Buff.String())
assert.DeepEqual(t, out.Buff.String(), query)
assert.DeepEqual(t, out.Args, args)
assert.Equal(t, out.Buff.String(), query)
assert.Equal(t, out.Args, args)
}
func assertProjectionSerialize(t *testing.T, projection Projection, query string, args ...interface{}) {
out := SQLBuilder{Dialect: defaultDialect}
projection.serializeForProjection(SelectStatementType, &out)
assert.DeepEqual(t, out.Buff.String(), query)
assert.DeepEqual(t, out.Args, args)
assert.Equal(t, out.Buff.String(), query)
assert.Equal(t, out.Args, args)
}

View file

@ -1,7 +1,7 @@
package jet
import (
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
)

View file

@ -7,21 +7,23 @@ import (
"github.com/go-jet/jet/internal/jet"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/qrm"
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
"github.com/google/go-cmp/cmp"
)
// AssertExec assert statement execution for successful execution and number of rows affected
func AssertExec(t *testing.T, stmt jet.Statement, db qrm.DB, rowsAffected ...int64) {
res, err := stmt.Exec(db)
assert.NilError(t, err)
assert.NoError(t, err)
rows, err := res.RowsAffected()
assert.NilError(t, err)
assert.NoError(t, err)
if len(rowsAffected) > 0 {
assert.Equal(t, rows, rowsAffected[0])
@ -49,7 +51,7 @@ func PrintJson(v interface{}) {
// AssertJSON check if data json output is the same as expectedJSON
func AssertJSON(t *testing.T, data interface{}, expectedJSON string) {
jsonData, err := json.MarshalIndent(data, "", "\t")
assert.NilError(t, err)
assert.NoError(t, err)
assert.Equal(t, "\n"+string(jsonData)+"\n", expectedJSON)
}
@ -69,17 +71,17 @@ func AssertJSONFile(t *testing.T, data interface{}, testRelativePath string) {
filePath := getFullPath(testRelativePath)
fileJSONData, err := ioutil.ReadFile(filePath)
assert.NilError(t, err)
assert.NoError(t, err)
if runtime.GOOS == "windows" {
fileJSONData = bytes.Replace(fileJSONData, []byte("\r\n"), []byte("\n"), -1)
}
jsonData, err := json.MarshalIndent(data, "", "\t")
assert.NilError(t, err)
assert.NoError(t, err)
assert.Assert(t, string(fileJSONData) == string(jsonData))
//assert.DeepEqual(t, string(fileJSONData), string(jsonData))
assert.True(t, string(fileJSONData) == string(jsonData))
//AssertDeepEqual(t, string(fileJSONData), string(jsonData))
}
// AssertStatementSql check if statement Sql() is the same as expectedQuery and expectedArgs
@ -90,7 +92,7 @@ func AssertStatementSql(t *testing.T, query jet.Statement, expectedQuery string,
if len(expectedArgs) == 0 {
return
}
assert.DeepEqual(t, args, expectedArgs)
AssertDeepEqual(t, args, expectedArgs)
}
// AssertStatementSqlErr checks if statement Sql() panics with errorStr
@ -108,7 +110,7 @@ func AssertDebugStatementSql(t *testing.T, query jet.Statement, expectedQuery st
_, args := query.Sql()
if len(expectedArgs) > 0 {
assert.DeepEqual(t, args, expectedArgs)
AssertDeepEqual(t, args, expectedArgs)
}
debuqSql := query.DebugSql()
@ -122,10 +124,10 @@ func AssertClauseSerialize(t *testing.T, dialect jet.Dialect, clause jet.Seriali
//fmt.Println(out.Buff.String())
assert.DeepEqual(t, out.Buff.String(), query)
AssertDeepEqual(t, out.Buff.String(), query)
if len(args) > 0 {
assert.DeepEqual(t, out.Args, args)
AssertDeepEqual(t, out.Args, args)
}
}
@ -134,10 +136,10 @@ func AssertDebugClauseSerialize(t *testing.T, dialect jet.Dialect, clause jet.Se
out := jet.SQLBuilder{Dialect: dialect, Debug: true}
jet.Serialize(clause, jet.SelectStatementType, &out)
assert.DeepEqual(t, out.Buff.String(), query)
AssertDeepEqual(t, out.Buff.String(), query)
if len(args) > 0 {
assert.DeepEqual(t, out.Args, args)
AssertDeepEqual(t, out.Args, args)
}
}
@ -167,8 +169,8 @@ func AssertProjectionSerialize(t *testing.T, dialect jet.Dialect, projection jet
out := jet.SQLBuilder{Dialect: dialect}
jet.SerializeForProjection(projection, jet.SelectStatementType, &out)
assert.DeepEqual(t, out.Buff.String(), query)
assert.DeepEqual(t, out.Args, args)
AssertDeepEqual(t, out.Buff.String(), query)
AssertDeepEqual(t, out.Args, args)
}
// AssertQueryPanicErr check if statement Query execution panics with error errString
@ -185,13 +187,13 @@ func AssertQueryPanicErr(t *testing.T, stmt jet.Statement, db qrm.DB, dest inter
func AssertFileContent(t *testing.T, filePath string, contentBegin string, expectedContent string) {
enumFileData, err := ioutil.ReadFile(filePath)
assert.NilError(t, err)
assert.NoError(t, err)
beginIndex := bytes.Index(enumFileData, []byte(contentBegin))
//fmt.Println("-"+string(enumFileData[beginIndex:])+"-")
assert.DeepEqual(t, string(enumFileData[beginIndex:]), expectedContent)
AssertDeepEqual(t, string(enumFileData[beginIndex:]), expectedContent)
}
// AssertFileNamesEqual check if all filesInfos are contained in fileNames
@ -205,6 +207,10 @@ func AssertFileNamesEqual(t *testing.T, fileInfos []os.FileInfo, fileNames ...st
}
for _, fileName := range fileNames {
assert.Assert(t, fileNamesMap[fileName], fileName+" does not exist.")
assert.True(t, fileNamesMap[fileName], fileName+" does not exist.")
}
}
func AssertDeepEqual(t *testing.T, actual, expected interface{}) {
assert.True(t, cmp.Equal(actual, expected))
}

View file

@ -2,7 +2,7 @@ package utils
import (
"fmt"
"gotest.tools/assert"
"github.com/stretchr/testify/assert"
"testing"
)