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

Function TestDeleteAndReadIndex

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

Source from the content-addressed store, hash-verified

134}
135
136func TestDeleteAndReadIndex(t *testing.T) {
137 // Add new predicate with several indices.
138 s1 := testSchema + "\n numerology: string @index(exact, term, fulltext) .\n"
139 setSchema(s1)
140 triples := `
141 <0x666> <numerology> "This number is evil" .
142 <0x777> <numerology> "This number is good" .
143 `
144 require.NoError(t, addTriplesToCluster(triples))
145
146 // Verify fulltext index works as expected.
147 q1 := `
148 {
149 me(func: anyoftext(numerology, "numbers")) {
150 uid
151 numerology
152 }
153 }`
154 js := processQueryNoErr(t, q1)
155 require.JSONEq(t, `{"data": {"me": [
156 {"uid": "0x666", "numerology": "This number is evil"},
157 {"uid": "0x777", "numerology": "This number is good"}
158 ]}}`, js)
159
160 // Remove the fulltext index and verify the previous query is no longer supported.
161 s2 := testSchema + "\n numerology: string @index(exact, term) .\n"
162 setSchema(s2)
163 _, err := processQuery(context.Background(), t, q1)
164 require.Error(t, err)
165 require.Contains(t, err.Error(), "Attribute numerology is not indexed with type fulltext")
166
167 // Verify term index still works as expected.
168 q2 := `
169 {
170 me(func: anyofterms(numerology, "number")) {
171 uid
172 numerology
173 }
174 }`
175 js = processQueryNoErr(t, q2)
176 require.JSONEq(t, `{"data": {"me": [
177 {"uid": "0x666", "numerology": "This number is evil"},
178 {"uid": "0x777", "numerology": "This number is good"}
179 ]}}`, js)
180
181 // Re-add index and verify that the original query works again.
182 setSchema(s1)
183 js = processQueryNoErr(t, q1)
184 require.JSONEq(t, `{"data": {"me": [
185 {"uid": "0x666", "numerology": "This number is evil"},
186 {"uid": "0x777", "numerology": "This number is good"}
187 ]}}`, js)
188
189 // Finally, drop the predicate and restore schema.
190 dropPredicate("numerology")
191 setSchema(testSchema)
192}
193

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