Skip to content

Commit

Permalink
test for issue cayleygraph#578
Browse files Browse the repository at this point in the history
  • Loading branch information
gkontos committed May 6, 2017
1 parent a10b207 commit 52ce6e6
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions graph/graphtest/graphtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestAll(t testing.TB, gen DatabaseFunc, conf *Config) {
}
TestLoadTypedQuads(t, gen, conf)
TestAddRemove(t, gen, conf)
TestReAddQuad(t, gen, conf)
TestIteratorsAndNextResultOrderA(t, gen)
if !conf.UnTyped {
TestCompareTypedValues(t, gen, conf)
Expand Down Expand Up @@ -661,6 +662,125 @@ func TestAddRemove(t testing.TB, gen DatabaseFunc, conf *Config) {
ExpectIteratedRawStrings(t, qs, all, expect)
}

// when a quad is deleted, it should be possible to readd the quad without an error
func TestReAddQuad(t testing.TB, gen DatabaseFunc, conf *Config) {
qs, opts, closer := gen(t)
defer closer()

if opts == nil {
opts = make(graph.Options)
}

w := MakeWriter(t, qs, opts, MakeQuadSet()...)

// This quad will be added, removed, and readded
testQuad := quad.MakeRaw("X", "follows", "B", "")

require.Equal(t, int64(11), qs.Size(), "Incorrect number of quads")

all := qs.NodesAllIterator()
expect := []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

// Add Test Quad which will be removed and readded
err := w.AddQuadSet([]quad.Quad{
testQuad,
})
assert.Nil(t, err, "AddQuadSet failed")

assert.Equal(t, int64(12), qs.Size(), "Incorrect number of quads")

all = qs.NodesAllIterator()
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

// Remove quad
err = w.RemoveQuad(testQuad)
require.Nil(t, err, "RemoveQuad failed")

if !conf.SkipNodeDelAfterQuadDel {
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"cool",
"follows",
"status",
"status_graph",
}
} else {
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
}

// Readd the deleted quad
err = w.AddQuadSet([]quad.Quad{
testQuad,
})
assert.Nil(t, err, "AddQuadSet failed")

assert.Equal(t, int64(12), qs.Size(), "Incorrect number of quads")

all = qs.NodesAllIterator()
expect = []string{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"X",
"cool",
"follows",
"status",
"status_graph",
}
ExpectIteratedRawStrings(t, qs, all, expect)

}

func TestIteratorsAndNextResultOrderA(t testing.TB, gen DatabaseFunc) {
qs, opts, closer := gen(t)
defer closer()
Expand Down

0 comments on commit 52ce6e6

Please sign in to comment.