| 888 | } |
| 889 | |
| 890 | func TestStringArrayScanError(t *testing.T) { |
| 891 | for _, tt := range []struct { |
| 892 | input, err string |
| 893 | }{ |
| 894 | {``, "unable to parse array"}, |
| 895 | {`{`, "unable to parse array"}, |
| 896 | {`{{a},{b}}`, "cannot convert ARRAY[2][1] to StringArray"}, |
| 897 | {`{NULL}`, "parsing array element index 0: cannot convert nil to string"}, |
| 898 | {`{a,NULL}`, "parsing array element index 1: cannot convert nil to string"}, |
| 899 | {`{a,b,NULL}`, "parsing array element index 2: cannot convert nil to string"}, |
| 900 | } { |
| 901 | arr := StringArray{"x", "x", "x"} |
| 902 | err := arr.Scan(tt.input) |
| 903 | |
| 904 | if err == nil { |
| 905 | t.Fatalf("Expected error for %q, got none", tt.input) |
| 906 | } |
| 907 | if !strings.Contains(err.Error(), tt.err) { |
| 908 | t.Errorf("Expected error to contain %q for %q, got %q", tt.err, tt.input, err) |
| 909 | } |
| 910 | if !reflect.DeepEqual(arr, StringArray{"x", "x", "x"}) { |
| 911 | t.Errorf("Expected destination not to change for %q, got %+v", tt.input, arr) |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | func TestStringArrayValue(t *testing.T) { |
| 917 | result, err := StringArray(nil).Value() |