sq/drivers/sqlserver/internal_test.go
Neil O'Toole 8cbcaf6606
Chore/update go modules ()
* switched to microsoft/go-mssqldb

* upgraded go.uber.org packages

* updated ryboe/q

* more package updates
2022-12-23 11:09:06 -07:00

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))
}