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

Function TestMultipleMutation

dgraph/cmd/alpha/upsert_test.go:2260–2335  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2258}
2259
2260func TestMultipleMutation(t *testing.T) {
2261 require.NoError(t, dropAll())
2262 require.NoError(t, alterSchema(`email: string @index(exact) .`))
2263
2264 m1 := `
2265upsert {
2266 query {
2267 q(func: eq(email, "email@company.io")) {
2268 v as uid
2269 }
2270 }
2271
2272 mutation @if(not(eq(len(v), 0))) {
2273 set {
2274 uid(v) <name> "not_name" .
2275 uid(v) <email> "not_email@company.io" .
2276 }
2277 }
2278
2279 mutation @if(eq(len(v), 0)) {
2280 set {
2281 _:user <name> "name" .
2282 _:user <email> "email@company.io" .
2283 }
2284 }
2285}`
2286 mr, err := mutationWithTs(mutationInp{body: m1, typ: "application/rdf", commitNow: true})
2287 require.NoError(t, err)
2288 require.True(t, len(mr.keys) == 0)
2289 require.Equal(t, []string{"email", "name"}, splitPreds(mr.preds))
2290 result := QueryResult{}
2291 require.NoError(t, json.Unmarshal(mr.data, &result))
2292 require.Equal(t, 0, len(result.Queries["q"]))
2293
2294 q1 := `
2295{
2296 q(func: eq(email, "email@company.io")) {
2297 name
2298 }
2299}`
2300 res, _, err := queryWithTs(queryInp{body: q1, typ: "application/dql"})
2301 expectedRes := `
2302{
2303 "data": {
2304 "q": [{
2305 "name": "name"
2306 }]
2307 }
2308}`
2309 require.NoError(t, err)
2310 testutil.CompareJSON(t, res, expectedRes)
2311
2312 // This time the other mutation will get executed
2313 _, err = mutationWithTs(mutationInp{body: m1, typ: "application/rdf", commitNow: true})
2314 require.NoError(t, err)
2315
2316 q2 := `
2317{

Callers

nothing calls this directly

Calls 6

CompareJSONFunction · 0.92
dropAllFunction · 0.85
alterSchemaFunction · 0.85
mutationWithTsFunction · 0.85
splitPredsFunction · 0.85
queryWithTsFunction · 0.85

Tested by

no test coverage detected