From b4dff7d9d25bce258176ce74d64a229d47f10327 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Mon, 28 Dec 2020 13:50:04 +0800 Subject: [PATCH] Add unit test case to improve test coverage for go/sqltypes/result.go Signed-off-by: Hu Shuai --- go/sqltypes/result_test.go | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/go/sqltypes/result_test.go b/go/sqltypes/result_test.go index bf2d9fd87fe..5ae455560cb 100644 --- a/go/sqltypes/result_test.go +++ b/go/sqltypes/result_test.go @@ -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) + } +}