Skip to content

Commit

Permalink
Add CreateTouchDeleteTouchTest
Browse files Browse the repository at this point in the history
  • Loading branch information
trrrrrys authored and josephschorr committed Aug 7, 2023
1 parent 0be7a11 commit 476337b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/datastore/test/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func AllWithExceptions(t *testing.T, tester DatastoreTester, except Categories)
t.Run("TestWriteDeleteWrite", func(t *testing.T) { WriteDeleteWriteTest(t, tester) })
t.Run("TestCreateAlreadyExisting", func(t *testing.T) { CreateAlreadyExistingTest(t, tester) })
t.Run("TestTouchAlreadyExisting", func(t *testing.T) { TouchAlreadyExistingTest(t, tester) })
t.Run("TestWriteDeleteTouchTest", func(t *testing.T) { WriteDeleteTouchTest(t, tester) })
t.Run("TestCreateDeleteTouchTest", func(t *testing.T) { CreateDeleteTouchTest(t, tester) })
t.Run("TestCreateTouchDeleteTouchTest", func(t *testing.T) { CreateTouchDeleteTouchTest(t, tester) })
t.Run("TestTouchAlreadyExistingCaveated", func(t *testing.T) { TouchAlreadyExistingCaveatedTest(t, tester) })

t.Run("TestMultipleReadsInRWT", func(t *testing.T) { MultipleReadsInRWTTest(t, tester) })
Expand Down
38 changes: 36 additions & 2 deletions pkg/datastore/test/tuples.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,8 @@ func TouchAlreadyExistingTest(t *testing.T, tester DatastoreTester) {
ensureTuples(ctx, require, ds, tpl1, tpl2, tpl3)
}

// WriteDeleteTouchTest tests writing a relationship, deleting it, and then touching it.
func WriteDeleteTouchTest(t *testing.T, tester DatastoreTester) {
// CreateDeleteTouchTest tests writing a relationship, deleting it, and then touching it.
func CreateDeleteTouchTest(t *testing.T, tester DatastoreTester) {
require := require.New(t)

rawDS, err := tester.New(0, veryLargeGCInterval, veryLargeGCWindow, 1)
Expand Down Expand Up @@ -627,6 +627,40 @@ func WriteDeleteTouchTest(t *testing.T, tester DatastoreTester) {
ensureTuples(ctx, require, ds, tpl1, tpl2)
}

// CreateTouchDeleteTouchTest tests writing a relationship, touching it, deleting it, and then touching it.
func CreateTouchDeleteTouchTest(t *testing.T, tester DatastoreTester) {
require := require.New(t)

rawDS, err := tester.New(0, veryLargeGCInterval, veryLargeGCWindow, 1)
require.NoError(err)

ds, _ := testfixtures.StandardDatastoreWithData(rawDS, require)
ctx := context.Background()

tpl1 := makeTestTuple("foo", "tom")
tpl2 := makeTestTuple("foo", "sarah")

_, err = common.WriteTuples(ctx, ds, core.RelationTupleUpdate_CREATE, tpl1, tpl2)
require.NoError(err)

ensureTuples(ctx, require, ds, tpl1, tpl2)

_, err = common.WriteTuples(ctx, ds, core.RelationTupleUpdate_TOUCH, tpl1, tpl2)
require.NoError(err)

ensureTuples(ctx, require, ds, tpl1, tpl2)

_, err = common.WriteTuples(ctx, ds, core.RelationTupleUpdate_DELETE, tpl1, tpl2)
require.NoError(err)

ensureNotTuples(ctx, require, ds, tpl1, tpl2)

_, err = common.WriteTuples(ctx, ds, core.RelationTupleUpdate_TOUCH, tpl1, tpl2)
require.NoError(err)

ensureTuples(ctx, require, ds, tpl1, tpl2)
}

// TouchAlreadyExistingCaveatedTest tests touching a relationship twice.
func TouchAlreadyExistingCaveatedTest(t *testing.T, tester DatastoreTester) {
require := require.New(t)
Expand Down

0 comments on commit 476337b

Please sign in to comment.