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

Function TestExportJson

worker/export_test.go:329–383  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

327}
328
329func TestExportJson(t *testing.T) {
330 // Index the name predicate. We ensure it doesn't show up on export.
331 initTestExport(t, `name: string @index(exact) .
332 [0x2] name: string @index(exact) .`)
333
334 bdir := t.TempDir()
335 time.Sleep(1 * time.Second)
336
337 // We have 4 friend type edges. FP("friends")%10 = 2.
338 x.WorkerConfig.ExportPath = bdir
339 readTs := timestamp()
340 // Do the following so export won't block forever for readTs.
341 posting.Oracle().ProcessDelta(&pb.OracleDelta{MaxAssigned: readTs})
342 req := pb.ExportRequest{ReadTs: readTs, GroupId: 1, Format: "json", Namespace: math.MaxUint64}
343 files, err := export(context.Background(), &req)
344 require.NoError(t, err)
345
346 fileList, schemaFileList, gqlSchema := getExportFileList(t, bdir)
347 require.Equal(t, len(files), len(fileList)+len(schemaFileList)+len(gqlSchema))
348
349 file := fileList[0]
350 f, err := os.Open(file)
351 require.NoError(t, err)
352
353 r, err := gzip.NewReader(f)
354 require.NoError(t, err)
355
356 wantJson := `
357 [
358 {"uid":"0x1","namespace":"0x0","name":"pho\ton"},
359 {"uid":"0x2","namespace":"0x0","name@en":"pho\ton"},
360 {"uid":"0x3","namespace":"0x0","name":"First Line\nSecondLine"},
361 {"uid":"0x5","namespace":"0x0","name":""},
362 {"uid":"0x6","namespace":"0x0","name":"Ding!\u0007Ding!\u0007Ding!\u0007"},
363 {"uid":"0x1","namespace":"0x0","friend":[{"uid":"0x5"}]},
364 {"uid":"0x2","namespace":"0x0","friend":[{"uid":"0x5"}]},
365 {"uid":"0x3","namespace":"0x0","friend":[{"uid":"0x5"}]},
366 {"uid":"0x4","namespace":"0x0","friend":[{"uid":"0x5","friend|age":33,
367 "friend|close":"true","friend|game":"football",
368 "friend|poem":"roses are red\nviolets are blue","friend|since":"2005-05-02T15:04:05Z"}]},
369 {"uid":"0x9","namespace":"0x2","name":"ns2"}
370 ]
371 `
372 gotJson, err := io.ReadAll(r)
373 require.NoError(t, err)
374 var expected interface{}
375 require.NoError(t, json.Unmarshal([]byte(wantJson), &expected))
376
377 var actual interface{}
378 require.NoError(t, json.Unmarshal(gotJson, &actual))
379 require.ElementsMatch(t, expected, actual)
380
381 checkExportSchema(t, schemaFileList)
382 checkExportGqlSchema(t, gqlSchema)
383}
384
385const exportRequest = `mutation export($format: String!) {
386 export(input: {format: $format}) {

Callers

nothing calls this directly

Calls 9

OracleFunction · 0.92
initTestExportFunction · 0.85
exportFunction · 0.85
getExportFileListFunction · 0.85
checkExportSchemaFunction · 0.85
checkExportGqlSchemaFunction · 0.85
ProcessDeltaMethod · 0.80
timestampFunction · 0.70
OpenMethod · 0.65

Tested by

no test coverage detected