Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Nov 7, 2024
1 parent 5c8397c commit 26aea7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/parser/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ func TestParseBlock(t *testing.T) {
version := RawBlockGetVersion(block)
t.Log(version)
length := RawBlockGetLength(block)
assert.Equal(t, int32(447), length)
assert.Equal(t, int32(448), length)
rows := RawBlockGetNumOfRows(block)
assert.Equal(t, int32(2), rows)
columns := RawBlockGetNumOfCols(block)
Expand Down
39 changes: 39 additions & 0 deletions common/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"database/sql/driver"
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -95,3 +96,41 @@ func TestInterpolateParams(t *testing.T) {
})
}
}

func TestValueArgsToNamedValueArgs(t *testing.T) {
tests := []struct {
name string
args []driver.Value
want []driver.NamedValue
}{
{
name: "empty args",
args: []driver.Value{},
want: []driver.NamedValue{},
},
{
name: "single arg",
args: []driver.Value{int64(1)},
want: []driver.NamedValue{
{Ordinal: 1, Value: int64(1)},
},
},
{
name: "multiple args",
args: []driver.Value{int64(1), "test", nil},
want: []driver.NamedValue{
{Ordinal: 1, Value: int64(1)},
{Ordinal: 2, Value: "test"},
{Ordinal: 3, Value: nil},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ValueArgsToNamedValueArgs(tt.args); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ValueArgsToNamedValueArgs() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 26aea7f

Please sign in to comment.