Skip to content

Commit

Permalink
Add logger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Jun 19, 2024
1 parent b58a4bc commit 18e015e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/connection/result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,11 @@ func (results *QueryResults) Next(dest []driver.Value) error {
}

for i := range dest {
dataType := results.data.Columns[i].DataType
value := results.data.Data[i][results.rowPointer]
dest[i] = convertResultSetValue(dataType, value)
dest[i] = results.data.Data[i][results.rowPointer]
}

results.rowPointer = results.rowPointer + 1
results.totalRowPointer = results.totalRowPointer + 1

return nil
}

func convertResultSetValue(dataType types.SqlQueryColumnType, value any) driver.Value {
return value
}
6 changes: 6 additions & 0 deletions pkg/connection/result_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ func (suite *ResultSetTestSuite) TestNextPointerDoesNotMatch() {
queryResults := QueryResults{data: &data, totalRowPointer: 2}
suite.EqualError(queryResults.Next(nil), "EOF")
}

func (suite *ResultSetTestSuite) TestCloseIgnoresResultHandleZero() {
data := types.SqlQueryResponseResultSetData{NumRows: 1, ResultSetHandle: 0}
queryResults := QueryResults{data: &data, totalRowPointer: 2}
suite.NoError(queryResults.Close())
}
19 changes: 19 additions & 0 deletions pkg/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ func TestErrorsSetLogger(t *testing.T) {
func TestLoggerIsNil(t *testing.T) {
assert.EqualError(t, SetLogger(nil), "E-EGOD-8: logger is nil")
}

func TestSetTraceLogger(t *testing.T) {
// set up logger
buffer := bytes.NewBuffer(make([]byte, 0, 64))
logger := log.New(buffer, "prefix: ", 0)

SetTraceLogger(logger)
defer SetTraceLogger(nil)
TraceLogger.Print("test")
const expected = "prefix: test\n"
if actual := buffer.String(); actual != expected {
t.Errorf("expected %q, got %q", expected, actual)
}
}

func TestDefaultTraceLogger(t *testing.T) {
TraceLogger.Print("ignored")
TraceLogger.Print("ignored %s", "arg")
}

0 comments on commit 18e015e

Please sign in to comment.