| 424 | } |
| 425 | |
| 426 | func TestBytesArrayScanError(t *testing.T) { |
| 427 | for _, tt := range []struct { |
| 428 | input, err string |
| 429 | }{ |
| 430 | {``, "unable to parse array"}, |
| 431 | {`{`, "unable to parse array"}, |
| 432 | {`{{"\\xfeff"},{"\\xbeef"}}`, "cannot convert ARRAY[2][1] to BytesArray"}, |
| 433 | {`{"\\abc"}`, "could not parse bytea array index 0: could not parse bytea value"}, |
| 434 | } { |
| 435 | arr := BytesArray{{2}, {6}, {0, 0}} |
| 436 | err := arr.Scan(tt.input) |
| 437 | |
| 438 | if err == nil { |
| 439 | t.Fatalf("Expected error for %q, got none", tt.input) |
| 440 | } |
| 441 | if !strings.Contains(err.Error(), tt.err) { |
| 442 | t.Errorf("Expected error to contain %q for %q, got %q", tt.err, tt.input, err) |
| 443 | } |
| 444 | if !reflect.DeepEqual(arr, BytesArray{{2}, {6}, {0, 0}}) { |
| 445 | t.Errorf("Expected destination not to change for %q, got %+v", tt.input, arr) |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | func TestBytesArrayValue(t *testing.T) { |
| 451 | result, err := BytesArray(nil).Value() |