(t *testing.T)
| 3395 | }, |
| 3396 | { |
| 3397 | name: "JSON metadata like Fivetran sends", |
| 3398 | input: "customer_id,metadata,type\ncust_123,\"{\"\"subscription\"\":\n \"\"active\"\",\n \"\"plan\"\": \"\"pro\"\"}\",invoice\n", |
| 3399 | delimiter: ",", |
| 3400 | expected: [][]string{{"customer_id", "metadata", "type"}, {"cust_123", "{\"subscription\":\n \"active\",\n \"plan\": \"pro\"}", "invoice"}}, |
| 3401 | }, |
| 3402 | { |
| 3403 | name: "13 columns with multiline JSON in middle", |
| 3404 | input: "c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13\nv1,v2,v3,v4,v5,v6,\"{\"\"a\"\":\n\"\"b\"\"}\",v8,v9,v10,v11,v12,v13\n", |
| 3405 | delimiter: ",", |
| 3406 | expected: [][]string{{"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13"}, {"v1", "v2", "v3", "v4", "v5", "v6", "{\"a\":\n\"b\"}", "v8", "v9", "v10", "v11", "v12", "v13"}}, |
| 3407 | }, |
| 3408 | } |
| 3409 | |
| 3410 | for _, tt := range tests { |
| 3411 | t.Run(tt.name, func(t *testing.T) { |
| 3412 | // Simulate what handleCopyIn does: use csv.Reader on entire buffer |
| 3413 | reader := csv.NewReader(strings.NewReader(tt.input)) |
| 3414 | reader.Comma = rune(tt.delimiter[0]) |
| 3415 | reader.LazyQuotes = true |
| 3416 | reader.FieldsPerRecord = -1 |
| 3417 | |
| 3418 | var rows [][]string |
| 3419 | for { |
| 3420 | record, err := reader.Read() |
| 3421 | if err == io.EOF { |
| 3422 | break |
| 3423 | } |
| 3424 | if err != nil { |
| 3425 | t.Fatalf("csv.Read() error: %v", err) |
| 3426 | } |
| 3427 | rows = append(rows, record) |
| 3428 | } |
| 3429 | |
| 3430 | if len(rows) != len(tt.expected) { |
| 3431 | t.Errorf("got %d rows, want %d\nGot: %v\nWant: %v", |
| 3432 | len(rows), len(tt.expected), rows, tt.expected) |
| 3433 | return |
| 3434 | } |
| 3435 | |
| 3436 | for i, row := range rows { |
| 3437 | if len(row) != len(tt.expected[i]) { |
| 3438 | t.Errorf("row %d: got %d columns, want %d\nGot: %v\nWant: %v", |
| 3439 | i, len(row), len(tt.expected[i]), row, tt.expected[i]) |
| 3440 | continue |
| 3441 | } |
| 3442 | for j, val := range row { |
| 3443 | if val != tt.expected[i][j] { |
| 3444 | t.Errorf("row %d col %d: got %q, want %q", |
| 3445 | i, j, val, tt.expected[i][j]) |
| 3446 | } |
nothing calls this directly
no test coverage detected