Skip to content

Commit

Permalink
PR: Test - Clean up panic assertions and skipping from change detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Oct 7, 2022
1 parent 3ef8b15 commit 067ff04
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
12 changes: 1 addition & 11 deletions tests/integration/query/one_to_many/with_cid_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package one_to_many
import (
"testing"

"github.com/stretchr/testify/assert"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand Down Expand Up @@ -62,15 +60,7 @@ func TestQueryOneToManyWithUnknownCidAndDocKey(t *testing.T) {
},
}

if testUtils.IsDetectingDbChanges() {
// The `assert.Panics` call will falsely fail if this test is executed during
// a detect changes test run
t.Skip()
}

assert.Panics(t, func() {
executeTestCase(t, test)
})
testUtils.AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
}

func TestQueryOneToManyWithCidAndDocKey(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package one_to_many_to_one
import (
"testing"

"github.com/stretchr/testify/assert"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand Down Expand Up @@ -134,9 +132,5 @@ func TestOneToManyToOneDeepOrderBySubTypeOfBothDescAndAsc(t *testing.T) {
Results: []map[string]any{},
}

assert.Panics(
t,
func() { executeTestCase(t, test) },
"expected a panic, but none found.",
)
testUtils.AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package one_to_many_to_one
import (
"testing"

"github.com/stretchr/testify/assert"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

Expand Down Expand Up @@ -302,11 +300,7 @@ func TestOneToManyToOneWithSumOfDeepOrderBySubTypeAndDeepOrderBySubtypeAscDirect
},
}

assert.Panics(
t,
func() { executeTestCase(t, test) },
"expected a panic, but none found.",
)
testUtils.AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
}

// TODO: Fix this panic in #833.
Expand Down Expand Up @@ -421,11 +415,7 @@ func TestOneToManyToOneWithSumOfDeepOrderBySubTypeOfBothDescAndAsc(t *testing.T)
Results: []map[string]any{},
}

assert.Panics(
t,
func() { executeTestCase(t, test) },
"expected a panic, but none found.",
)
testUtils.AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
}

// TODO: Fix this panic in #833.
Expand Down Expand Up @@ -542,9 +532,5 @@ func TestOneToManyToOneWithSumOfDeepOrderBySubTypeAndDeepOrderBySubtypeOppositeD
Results: []map[string]any{},
}

assert.Panics(
t,
func() { executeTestCase(t, test) },
"expected a panic, but none found.",
)
testUtils.AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
}
13 changes: 13 additions & 0 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ func IsDetectingDbChanges() bool {
return detectDbChanges
}

// AssertPanicAndSkipChangeDetection asserts that the code of function actually panics,
// also ensures the change detection is skipped so no false fails happen.
//
// Usage: AssertPanicAndSkipChangeDetection(t, func() { executeTestCase(t, test) })
func AssertPanicAndSkipChangeDetection(t *testing.T, f assert.PanicTestFunc) bool {
if IsDetectingDbChanges() {
// The `assert.Panics` call will falsely fail if this test is executed during
// a detect changes test run
t.Skip()
}
return assert.Panics(t, f, "expected a panic, but none found.")
}

func NewBadgerMemoryDB(ctx context.Context, dbopts ...db.Option) (databaseInfo, error) {
opts := badgerds.Options{Options: badger.DefaultOptions("").WithInMemory(true)}
rootstore, err := badgerds.NewDatastore("", &opts)
Expand Down

0 comments on commit 067ff04

Please sign in to comment.