func makeTestStore(data []quad.Quad, opts graph.Options) (graph.QuadStore, graph.QuadWriter, []pair) { seen := make(map[string]struct{}) qs, _ := newQuadStore("", opts) qs, _ = newQuadStoreForRequest(qs, opts) var ( val int64 ind []pair ) writer, _ := writer.NewSingleReplication(qs, nil) for _, t := range data { for _, qp := range []string{t.Subject, t.Predicate, t.Object, t.Label} { if _, ok := seen[qp]; !ok && qp != "" { val++ ind = append(ind, pair{qp, val}) seen[qp] = struct{}{} } } } writer.AddQuadSet(data) return qs, writer, ind }
func TestAddRemove(t *testing.T) { inst, opts, err := createInstance() defer inst.Close() if err != nil { t.Fatalf("failed to create instance: %v", err) } // Add quads qs, writer, _ := makeTestStore(simpleGraph, opts) if qs.Size() != 11 { t.Fatal("Incorrect number of quads") } all := qs.NodesAllIterator() expect := []string{ "A", "B", "C", "D", "E", "F", "G", "follows", "status", "cool", "status_graph", } if got, ok := compareResults(qs, all, expect); !ok { t.Errorf("Unexpected iterated result, got:%v expect:%v", got, expect) } // Add more quads, some conflicts if err := writer.AddQuadSet(simpleGraphUpdate); err != nil { t.Errorf("AddQuadSet failed, %v", err) } if qs.Size() != 13 { t.Fatal("Incorrect number of quads") } all = qs.NodesAllIterator() expect = []string{ "A", "B", "C", "D", "E", "F", "G", "X", "follows", "status", "cool", "status_graph", } if got, ok := compareResults(qs, all, expect); !ok { t.Errorf("Unexpected iterated result, got:%v expect:%v", got, expect) } // Remove quad toRemove := quad.Quad{"X", "follows", "B", ""} err = writer.RemoveQuad(toRemove) if err != nil { t.Errorf("RemoveQuad failed: %v", err) } expect = []string{ "A", "B", "C", "D", "E", "F", "G", "follows", "status", "cool", "status_graph", } if got, ok := compareResults(qs, all, expect); !ok { t.Errorf("Unexpected iterated result, got:%v expect:%v", got, expect) } }