@@ -16,6 +16,7 @@ package bigquery
16
16
17
17
import (
18
18
"errors"
19
+ "fmt"
19
20
"strconv"
20
21
"testing"
21
22
@@ -113,22 +114,27 @@ func TestHandleInsertErrors(t *testing.T) {
113
114
{InsertId : "b" },
114
115
}
115
116
for _ , test := range []struct {
116
- in []* bq.TableDataInsertAllResponseInsertErrors
117
- want error
117
+ description string
118
+ in []* bq.TableDataInsertAllResponseInsertErrors
119
+ want error
118
120
}{
119
121
{
120
- in : nil ,
121
- want : nil ,
122
+ description : "nil error" ,
123
+ in : nil ,
124
+ want : nil ,
122
125
},
123
126
{
124
- in : []* bq.TableDataInsertAllResponseInsertErrors {{Index : 1 }},
125
- want : PutMultiError {RowInsertionError {InsertID : "b" , RowIndex : 1 }},
127
+ description : "single error last row" ,
128
+ in : []* bq.TableDataInsertAllResponseInsertErrors {{Index : 1 }},
129
+ want : PutMultiError {RowInsertionError {InsertID : "b" , RowIndex : 1 }},
126
130
},
127
131
{
128
- in : []* bq.TableDataInsertAllResponseInsertErrors {{Index : 1 }},
129
- want : PutMultiError {RowInsertionError {InsertID : "b" , RowIndex : 1 }},
132
+ description : "single error first row" ,
133
+ in : []* bq.TableDataInsertAllResponseInsertErrors {{Index : 0 }},
134
+ want : PutMultiError {RowInsertionError {InsertID : "a" , RowIndex : 0 }},
130
135
},
131
136
{
137
+ description : "errors with extended message" ,
132
138
in : []* bq.TableDataInsertAllResponseInsertErrors {
133
139
{Errors : []* bq.ErrorProto {{Message : "m0" }}, Index : 0 },
134
140
{Errors : []* bq.ErrorProto {{Message : "m1" }}, Index : 1 },
@@ -138,11 +144,28 @@ func TestHandleInsertErrors(t *testing.T) {
138
144
RowInsertionError {InsertID : "b" , RowIndex : 1 , Errors : []error {& Error {Message : "m1" }}},
139
145
},
140
146
},
147
+ {
148
+ description : "invalid index" ,
149
+ in : []* bq.TableDataInsertAllResponseInsertErrors {
150
+ {Errors : []* bq.ErrorProto {{Message : "m0" }}, Index : 2 },
151
+ },
152
+ want : fmt .Errorf ("internal error: unexpected row index: 2" ),
153
+ },
141
154
} {
142
155
got := handleInsertErrors (test .in , rows )
143
- if ! testutil .Equal (got , test .want ) {
144
- t .Errorf ("%#v:\n got\n %#v\n want\n %#v" , test .in , got , test .want )
156
+ if _ , ok := got .(PutMultiError ); ok {
157
+ // compare structure of the PutMultiError
158
+ if ! testutil .Equal (got , test .want ) {
159
+ t .Errorf ("(case: %s)\n in %#v\n got\n %#v\n want\n %#v" , test .description , test .in , got , test .want )
160
+ }
161
+ continue
162
+ }
163
+
164
+ if got != nil && test .want != nil && got .Error () != test .want .Error () {
165
+ // check matching error messages
166
+ t .Errorf ("(case: %s)\n in %#v:\n got\n %#v\n want\n %#v" , test .description , test .in , got , test .want )
145
167
}
168
+
146
169
}
147
170
}
148
171
0 commit comments