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

Function populateGraphExport

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

Source from the content-addressed store, hash-verified

62}
63
64func populateGraphExport(t *testing.T) {
65 rdfEdges := []string{
66 `<1> <friend> <5> .`,
67 `<2> <friend> <5> .`,
68 `<3> <friend> <5> .`,
69 `<4> <friend> <5> (since=2005-05-02T15:04:05,close=true,` +
70 `age=33,game="football",poem="roses are red\nviolets are blue") .`,
71 `<1> <name> "pho\ton\u0000" .`,
72 `<2> <name> "pho\ton"@en .`,
73 `<3> <name> "First Line\nSecondLine" .`,
74 "<1> <friend_not_served> <5> .",
75 `<5> <name> "" .`,
76 `<6> <name> "Ding!\u0007Ding!\u0007Ding!\u0007" .`,
77 `<7> <name> "node_to_delete" .`,
78 fmt.Sprintf("<8> <dgraph.graphql.schema> \"%s\" .", gqlSchema),
79 `<8> <dgraph.graphql.xid> "dgraph.graphql.schema" .`,
80 `<8> <dgraph.type> "dgraph.graphql" .`,
81 `<9> <name> "ns2" <0x2> .`,
82 `<10> <name> "ns2_node_to_delete" <0x2> .`,
83 }
84 // This triplet will be deleted to ensure deleted nodes do not affect the output of the export.
85 edgesToDelete := []string{
86 `<7> <name> "node_to_delete" .`,
87 `<10> <name> "ns2_node_to_delete" <0x2> .`,
88 }
89
90 idMap := map[string]uint64{
91 "1": 1,
92 "2": 2,
93 "3": 3,
94 "4": 4,
95 "5": 5,
96 "6": 6,
97 "7": 7,
98 }
99
100 l := &lex.Lexer{}
101 processEdge := func(edge string, set bool) {
102 nq, err := chunker.ParseRDF(edge, l)
103 require.NoError(t, err)
104 rnq := dql.NQuad{NQuad: &nq}
105 require.NoError(t, facets.SortAndValidate(rnq.Facets))
106 e, err := rnq.ToEdgeUsing(idMap)
107 e.Attr = x.NamespaceAttr(nq.Namespace, e.Attr)
108 require.NoError(t, err)
109 if set {
110 addEdge(t, e, getOrCreate(x.DataKey(e.Attr, e.Entity)))
111 } else {
112 delEdge(t, e, getOrCreate(x.DataKey(e.Attr, e.Entity)))
113 }
114 }
115
116 for _, edge := range rdfEdges {
117 processEdge(edge, true)
118 }
119 for _, edge := range edgesToDelete {
120 processEdge(edge, false)
121 }

Callers 1

initTestExportFunction · 0.85

Calls 8

ToEdgeUsingMethod · 0.95
ParseRDFFunction · 0.92
SortAndValidateFunction · 0.92
NamespaceAttrFunction · 0.92
DataKeyFunction · 0.92
addEdgeFunction · 0.85
getOrCreateFunction · 0.85
delEdgeFunction · 0.85

Tested by

no test coverage detected