mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-21 07:01:41 +03:00
8cbcaf6606
* switched to microsoft/go-mssqldb * upgraded go.uber.org packages * updated ryboe/q * more package updates
44 lines
887 B
Go
44 lines
887 B
Go
package sqlserver
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
mssql "github.com/microsoft/go-mssqldb"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_placeholders(t *testing.T) {
|
|
testCases := []struct {
|
|
numCols int
|
|
numRows int
|
|
want string
|
|
}{
|
|
{numCols: 0, numRows: 0, want: ""},
|
|
{numCols: 1, numRows: 1, want: "(@p1)"},
|
|
{numCols: 2, numRows: 1, want: "(@p1, @p2)"},
|
|
{numCols: 1, numRows: 2, want: "(@p1), (@p2)"},
|
|
{numCols: 2, numRows: 2, want: "(@p1, @p2), (@p3, @p4)"},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
got := placeholders(tc.numCols, tc.numRows)
|
|
require.Equal(t, tc.want, got)
|
|
}
|
|
}
|
|
|
|
func Test_hasErrCode(t *testing.T) {
|
|
const wantCode = 100
|
|
var err error
|
|
|
|
require.False(t, hasErrCode(nil, wantCode))
|
|
err = fmt.Errorf("huzzah")
|
|
require.False(t, hasErrCode(err, wantCode))
|
|
|
|
err = mssql.Error{
|
|
Number: wantCode,
|
|
}
|
|
|
|
require.True(t, hasErrCode(err, wantCode))
|
|
}
|