MCPcopy
hub / github.com/cayleygraph/cayley / TestAddRemove

Function TestAddRemove

graph/graphtest/graphtest.go:847–939  ·  view source on GitHub ↗

TODO(dennwc): add tests to verify that QS behaves in a right way with IgnoreOptions, returns ErrQuadExists, ErrQuadNotExists is doing rollback.

(t testing.TB, gen testutil.DatabaseFunc, conf *Config)

Source from the content-addressed store, hash-verified

845// TODO(dennwc): add tests to verify that QS behaves in a right way with IgnoreOptions,
846// returns ErrQuadExists, ErrQuadNotExists is doing rollback.
847func TestAddRemove(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
848 qs, opts, closer := gen(t)
849 defer closer()
850
851 if opts == nil {
852 opts = make(graph.Options)
853 }
854 opts["ignore_duplicate"] = true
855
856 w := testutil.MakeWriter(t, qs, opts, MakeQuadSet()...)
857
858 exp := graph.Stats{
859 Nodes: graph.Size{Size: 11, Exact: true},
860 Quads: graph.Size{Size: 11, Exact: true},
861 }
862 st, err := qs.Stats(context.Background(), true)
863 require.NoError(t, err)
864 require.Equal(t, exp, st, "Unexpected quadstore size")
865
866 all := qs.NodesAllIterator()
867 expect := []string{
868 "A",
869 "B",
870 "C",
871 "D",
872 "E",
873 "F",
874 "G",
875 "cool",
876 "follows",
877 "status",
878 "status_graph",
879 }
880 ExpectIteratedRawStrings(t, qs, all, expect)
881
882 // Add more quads, some conflicts
883 err = w.AddQuadSet([]quad.Quad{
884 quad.Make("A", "follows", "B", nil), // duplicate
885 quad.Make("F", "follows", "B", nil),
886 quad.Make("C", "follows", "D", nil), // duplicate
887 quad.Make("X", "follows", "B", nil),
888 })
889 assert.Nil(t, err, "AddQuadSet failed")
890
891 exp = graph.Stats{
892 Nodes: graph.Size{Size: 12, Exact: true},
893 Quads: graph.Size{Size: 13, Exact: true},
894 }
895 st, err = qs.Stats(context.Background(), true)
896 require.NoError(t, err)
897 require.Equal(t, exp, st, "Unexpected quadstore size")
898
899 all = qs.NodesAllIterator()
900 expect = []string{
901 "A",
902 "B",
903 "C",
904 "D",

Callers

nothing calls this directly

Calls 8

MakeWriterFunction · 0.92
IsQuadNotExistFunction · 0.92
MakeQuadSetFunction · 0.85
ExpectIteratedRawStringsFunction · 0.85
StatsMethod · 0.65
NodesAllIteratorMethod · 0.65
AddQuadSetMethod · 0.65
RemoveQuadMethod · 0.65

Tested by

no test coverage detected