mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 14:11:45 +03:00
929b81c6d3
* mysql inspect performance * tidying up mysql metadata
46 lines
946 B
Go
46 lines
946 B
Go
package mysql
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/go-sql-driver/mysql"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/libsq/errz"
|
|
)
|
|
|
|
var KindFromDBTypeName = kindFromDBTypeName
|
|
|
|
func TestPlaceholders(t *testing.T) {
|
|
testCases := []struct {
|
|
numCols int
|
|
numRows int
|
|
want string
|
|
}{
|
|
{numCols: 0, numRows: 0, want: ""},
|
|
{numCols: 1, numRows: 1, want: "(?)"},
|
|
{numCols: 2, numRows: 1, want: "(?, ?)"},
|
|
{numCols: 1, numRows: 2, want: "(?), (?)"},
|
|
{numCols: 2, numRows: 2, want: "(?, ?), (?, ?)"},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
got := placeholders(tc.numCols, tc.numRows)
|
|
require.Equal(t, tc.want, got)
|
|
}
|
|
}
|
|
|
|
func TestHasErrCode(t *testing.T) {
|
|
var err error
|
|
err = &mysql.MySQLError{
|
|
Number: 1146,
|
|
Message: "I'm not here",
|
|
}
|
|
|
|
require.True(t, hasErrCode(err, errNumTableNotExist))
|
|
|
|
// Test that a wrapped error works
|
|
err = errz.Err(err)
|
|
require.True(t, hasErrCode(err, errNumTableNotExist))
|
|
}
|