Skip to content

Commit

Permalink
Add unit test case to improve test coverage for go/sqltypes/result.go
Browse files Browse the repository at this point in the history
Signed-off-by: Hu Shuai <[email protected]>
  • Loading branch information
hs0210 committed Dec 28, 2020
1 parent 4df037d commit b4dff7d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions go/sqltypes/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,53 @@ func TestStripMetaData(t *testing.T) {
}
}
}

func TestAppendResult(t *testing.T) {
src := &Result{
Fields: []*querypb.Field{{
Type: Int64,
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 2,
Rows: [][]Value{
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
{TestValue(Int64, "3"), TestValue(VarChar, "")},
},
}

result := &Result{
Fields: []*querypb.Field{{
Type: Int64,
}, {
Type: VarChar,
}},
InsertID: 3,
RowsAffected: 4,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
},
}

want := &Result{
Fields: []*querypb.Field{{
Type: Int64,
}, {
Type: VarChar,
}},
InsertID: 1,
RowsAffected: 6,
Rows: [][]Value{
{TestValue(Int64, "1"), MakeTrusted(Null, nil)},
{TestValue(Int64, "2"), MakeTrusted(VarChar, nil)},
{TestValue(Int64, "3"), TestValue(VarChar, "")},
},
}

result.AppendResult(src)

if !reflect.DeepEqual(result, want) {
t.Errorf("Got:\n%#v, want:\n%#v", result, want)
}
}

0 comments on commit b4dff7d

Please sign in to comment.