MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / TestDeleteAndReadCount

Function TestDeleteAndReadCount

query/query4_test.go:194–236  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

192}
193
194func TestDeleteAndReadCount(t *testing.T) {
195 // Add new predicate with count index.
196 s1 := testSchema + "\n numerology: string @count .\n"
197 setSchema(s1)
198 triples := `
199 <0x666> <numerology> "This number is evil" .
200 <0x777> <numerology> "This number is good" .
201 `
202 require.NoError(t, addTriplesToCluster(triples))
203
204 // Verify count index works as expected.
205 q1 := `
206 {
207 me(func: gt(count(numerology), 0)) {
208 uid
209 numerology
210 }
211 }`
212 js := processQueryNoErr(t, q1)
213 require.JSONEq(t, `{"data": {"me": [
214 {"uid": "0x666", "numerology": "This number is evil"},
215 {"uid": "0x777", "numerology": "This number is good"}
216 ]}}`, js)
217
218 // Remove the count index and verify the previous query is no longer supported.
219 s2 := testSchema + "\n numerology: string .\n"
220 setSchema(s2)
221 _, err := processQuery(context.Background(), t, q1)
222 require.Error(t, err)
223 require.Contains(t, err.Error(), "Need @count directive in schema for attr: numerology")
224
225 // Re-add count index and verify that the original query works again.
226 setSchema(s1)
227 js = processQueryNoErr(t, q1)
228 require.JSONEq(t, `{"data": {"me": [
229 {"uid": "0x666", "numerology": "This number is evil"},
230 {"uid": "0x777", "numerology": "This number is good"}
231 ]}}`, js)
232
233 // Finally, drop the predicate and restore schema.
234 dropPredicate("numerology")
235 setSchema(testSchema)
236}
237
238func TestDeleteAndReadReverse(t *testing.T) {
239 // Add new predicate with a reverse edge.

Callers

nothing calls this directly

Calls 6

setSchemaFunction · 0.70
addTriplesToClusterFunction · 0.70
processQueryNoErrFunction · 0.70
processQueryFunction · 0.70
dropPredicateFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…