(t *testing.T)
| 164 | } |
| 165 | |
| 166 | func TestAddMutation(t *testing.T) { |
| 167 | key := x.DataKey(x.AttrInRootNamespace("name"), 2) |
| 168 | |
| 169 | txn := NewTxn(1) |
| 170 | l, err := txn.Get(key) |
| 171 | require.NoError(t, err) |
| 172 | |
| 173 | edge := &pb.DirectedEdge{ |
| 174 | ValueId: 9, |
| 175 | Facets: []*api.Facet{{Key: "testing"}}, |
| 176 | } |
| 177 | addMutationHelper(t, l, edge, Set, txn) |
| 178 | |
| 179 | require.Equal(t, listToArray(t, 0, l, 1), []uint64{9}) |
| 180 | |
| 181 | p := getFirst(t, l, 1) |
| 182 | require.NotNil(t, p, "Unable to retrieve posting") |
| 183 | require.EqualValues(t, "testing", p.Facets[0].Key) |
| 184 | |
| 185 | // Add another edge now. |
| 186 | edge.ValueId = 81 |
| 187 | addMutationHelper(t, l, edge, Set, txn) |
| 188 | require.Equal(t, listToArray(t, 0, l, 1), []uint64{9, 81}) |
| 189 | |
| 190 | // Add another edge, in between the two above. |
| 191 | edge.ValueId = 49 |
| 192 | addMutationHelper(t, l, edge, Set, txn) |
| 193 | require.Equal(t, listToArray(t, 0, l, 1), []uint64{9, 49, 81}) |
| 194 | |
| 195 | checkUids(t, l, []uint64{9, 49, 81}, 1) |
| 196 | |
| 197 | // Delete an edge, add an edge, replace an edge |
| 198 | edge.ValueId = 49 |
| 199 | addMutationHelper(t, l, edge, Del, txn) |
| 200 | |
| 201 | edge.ValueId = 69 |
| 202 | addMutationHelper(t, l, edge, Set, txn) |
| 203 | |
| 204 | edge.ValueId = 9 |
| 205 | edge.Facets = []*api.Facet{{Key: "anti-testing"}} |
| 206 | addMutationHelper(t, l, edge, Set, txn) |
| 207 | require.NoError(t, l.commitMutation(1, 2)) |
| 208 | |
| 209 | uids := []uint64{9, 69, 81} |
| 210 | checkUids(t, l, uids, 3) |
| 211 | |
| 212 | p = getFirst(t, l, 3) |
| 213 | require.NotNil(t, p, "Unable to retrieve posting") |
| 214 | require.EqualValues(t, "anti-testing", p.Facets[0].Key) |
| 215 | } |
| 216 | |
| 217 | func getFirst(t *testing.T, l *List, readTs uint64) (res pb.Posting) { |
| 218 | require.NoError(t, l.Iterate(readTs, 0, func(p *pb.Posting) error { |
nothing calls this directly
no test coverage detected