MCPcopy
hub / github.com/dgraph-io/dgraph / TestChunkJSONMapAndArray

Function TestChunkJSONMapAndArray

chunker/chunk_test.go:46–77  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func 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.
80func TestJSONLoadReadNext(t *testing.T) {

Callers

nothing calls this directly

Calls 4

ChunkMethod · 0.95
NewChunkerFunction · 0.85
bufioReaderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected