(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func TestChunkJSONMapAndArray(t *testing.T) { |
| 47 | tests := []struct { |
| 48 | json string |
| 49 | chunks []string |
| 50 | }{ |
| 51 | {`[]`, []string{"[]"}}, |
| 52 | {`[{}]`, []string{"[{}]"}}, |
| 53 | {`[{"user": "alice"}]`, []string{`[{"user":"alice"}]`}}, |
| 54 | {`[{"user": "alice", "age": 26}]`, []string{`[{"user":"alice","age":26}]`}}, |
| 55 | {`[{"user": "alice", "age": 26}, {"name": "bob"}]`, []string{`[{"user":"alice","age":26},{"name":"bob"}]`}}, |
| 56 | } |
| 57 | |
| 58 | for _, test := range tests { |
| 59 | chunker := NewChunker(JsonFormat, 1000) |
| 60 | r := bufioReader(test.json) |
| 61 | var chunks []string |
| 62 | for { |
| 63 | chunkBuf, err := chunker.Chunk(r) |
| 64 | if err != nil { |
| 65 | require.Equal(t, io.EOF, err, "Received error for %s", test) |
| 66 | } |
| 67 | |
| 68 | chunks = append(chunks, chunkBuf.String()) |
| 69 | |
| 70 | if err == io.EOF { |
| 71 | break |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | require.Equal(t, test.chunks, chunks, "Got different chunks") |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Test that problems at the start of the next chunk are caught. |
| 80 | func TestJSONLoadReadNext(t *testing.T) { |
nothing calls this directly
no test coverage detected