2020-08-12 21:24:01 +03:00
|
|
|
package sqlserver
|
|
|
|
|
|
|
|
import (
|
2022-12-18 07:31:06 +03:00
|
|
|
"fmt"
|
2020-08-12 21:24:01 +03:00
|
|
|
"testing"
|
|
|
|
|
2022-12-23 21:09:06 +03:00
|
|
|
mssql "github.com/microsoft/go-mssqldb"
|
2020-08-12 21:24:01 +03:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-12-18 07:31:06 +03:00
|
|
|
func Test_placeholders(t *testing.T) {
|
2020-08-12 21:24:01 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2022-12-18 07:31:06 +03:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|