Skip to content

Commit

Permalink
test: Allow test harness to execute benchmarks (#2740)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2739

## Description

Allows test harness to execute benchmark tests as well as normal-tests.
  • Loading branch information
AndrewSisley authored Jun 19, 2024
1 parent 6573d8c commit e3eca29
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tests/change_detector/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func DatabaseDir(t testing.TB) string {
}

// PreTestChecks skips any test that can't be run by the change detector.
func PreTestChecks(t *testing.T, collectionNames []string) {
func PreTestChecks(t testing.TB, collectionNames []string) {
if !Enabled {
return
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func trimSubNodes(graph any) any {

// trimExplainAttributes trims away all keys that aren't plan nodes within the explain graph.
func trimExplainAttributes(
t *testing.T,
t testing.TB,
description string,
actualResult any,
) map[string]any {
Expand Down Expand Up @@ -411,7 +411,7 @@ func trimExplainAttributes(

// trimExplainAttributesArray is a helper that runs trimExplainAttributes for each item in an array.
func trimExplainAttributesArray[T any](
t *testing.T,
t testing.TB,
description string,
actualResult []T,
) []map[string]any {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/explain_result_asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ExplainResultAsserter struct {
planExecutions immutable.Option[uint64]
}

func readNumberProp(t *testing.T, val any, prop string) uint64 {
func readNumberProp(t testing.TB, val any, prop string) uint64 {
switch v := val.(type) {
case uint64:
return v
Expand All @@ -55,7 +55,7 @@ func readNumberProp(t *testing.T, val any, prop string) uint64 {
return 0
}

func (a *ExplainResultAsserter) Assert(t *testing.T, result []dataMap) {
func (a *ExplainResultAsserter) Assert(t testing.TB, result []dataMap) {
require.Len(t, result, 1, "Expected len(result) = 1, got %d", len(result))
explainNode, ok := result[0]["explain"].(dataMap)
require.True(t, ok, "Expected explain none")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type AnyOf []any
// assertResultsAnyOf asserts that actual result is equal to at least one of the expected results.
//
// The comparison is relaxed when using client types other than goClientType.
func assertResultsAnyOf(t *testing.T, client ClientType, expected AnyOf, actual any, msgAndArgs ...any) {
func assertResultsAnyOf(t testing.TB, client ClientType, expected AnyOf, actual any, msgAndArgs ...any) {
switch client {
case HTTPClientType, CLIClientType:
if !areResultsAnyOf(expected, actual) {
Expand All @@ -42,7 +42,7 @@ func assertResultsAnyOf(t *testing.T, client ClientType, expected AnyOf, actual
// assertResultsEqual asserts that actual result is equal to the expected result.
//
// The comparison is relaxed when using client types other than goClientType.
func assertResultsEqual(t *testing.T, client ClientType, expected any, actual any, msgAndArgs ...any) {
func assertResultsEqual(t testing.TB, client ClientType, expected any, actual any, msgAndArgs ...any) {
switch client {
case HTTPClientType, CLIClientType:
if !areResultsEqual(expected, actual) {
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type state struct {
ctx context.Context

// The Go Test test state
t *testing.T
t testing.TB

// The TestCase currently being executed.
testCase TestCase
Expand Down Expand Up @@ -88,7 +88,7 @@ type state struct {
// newState returns a new fresh state for the given testCase.
func newState(
ctx context.Context,
t *testing.T,
t testing.TB,
testCase TestCase,
dbt DatabaseType,
clientType ClientType,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@ type GetIndexes struct {
// assertions.
type ResultAsserter interface {
// Assert will be called with the test and the result of the request.
Assert(t *testing.T, result []map[string]any)
Assert(t testing.TB, result []map[string]any)
}

// ResultAsserterFunc is a function that can be used to implement the ResultAsserter
type ResultAsserterFunc func(*testing.T, []map[string]any) (bool, string)
type ResultAsserterFunc func(testing.TB, []map[string]any) (bool, string)

func (f ResultAsserterFunc) Assert(t *testing.T, result []map[string]any) {
func (f ResultAsserterFunc) Assert(t testing.TB, result []map[string]any) {
f(t, result)
}

Expand Down
26 changes: 13 additions & 13 deletions tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func AssertPanic(t *testing.T, f assert.PanicTestFunc) bool {
// Will also attempt to detect incompatible changes in the persisted data if
// configured to do so (the CI will do so, but disabled by default as it is slow).
func ExecuteTestCase(
t *testing.T,
t testing.TB,
testCase TestCase,
) {
flattenActions(&testCase)
Expand Down Expand Up @@ -181,7 +181,7 @@ func ExecuteTestCase(

func executeTestCase(
ctx context.Context,
t *testing.T,
t testing.TB,
collectionNames []string,
testCase TestCase,
dbt DatabaseType,
Expand Down Expand Up @@ -578,7 +578,7 @@ func flattenActions(testCase *TestCase) {
//
// If a SetupComplete action is provided, the actions will be split there, if not
// they will be split at the first non SchemaUpdate/CreateDoc/UpdateDoc action.
func getActionRange(t *testing.T, testCase TestCase) (int, int) {
func getActionRange(t testing.TB, testCase TestCase) (int, int) {
startIndex := 0
endIndex := len(testCase.Actions) - 1

Expand Down Expand Up @@ -927,7 +927,7 @@ func getIndexes(
func assertIndexesListsEqual(
expectedIndexes []client.IndexDescription,
actualIndexes []client.IndexDescription,
t *testing.T,
t testing.TB,
testDescription string,
) {
toNames := func(indexes []client.IndexDescription) []string {
Expand Down Expand Up @@ -956,7 +956,7 @@ func assertIndexesListsEqual(
}

func assertIndexesEqual(expectedIndex, actualIndex client.IndexDescription,
t *testing.T,
t testing.TB,
testDescription string,
) {
assert.Equal(t, expectedIndex.Name, actualIndex.Name, testDescription)
Expand Down Expand Up @@ -1767,7 +1767,7 @@ func executeSubscriptionRequest(

// Asserts as to whether an error has been raised as expected (or not). If an expected
// error has been raised it will return true, returns false in all other cases.
func AssertError(t *testing.T, description string, err error, expectedError string) bool {
func AssertError(t testing.TB, description string, err error, expectedError string) bool {
if err == nil {
return false
}
Expand All @@ -1788,7 +1788,7 @@ func AssertError(t *testing.T, description string, err error, expectedError stri
// Asserts as to whether an error has been raised as expected (or not). If an expected
// error has been raised it will return true, returns false in all other cases.
func AssertErrors(
t *testing.T,
t testing.TB,
description string,
errs []error,
expectedError string,
Expand Down Expand Up @@ -1888,7 +1888,7 @@ func assertRequestResults(
return false
}

func assertExpectedErrorRaised(t *testing.T, description string, expectedError string, wasRaised bool) {
func assertExpectedErrorRaised(t testing.TB, description string, expectedError string, wasRaised bool) {
if expectedError != "" && !wasRaised {
assert.Fail(t, "Expected an error however none was raised.", description)
}
Expand Down Expand Up @@ -1974,7 +1974,7 @@ func assertClientIntrospectionResults(

// Asserts that the `actual` contains the given `contains` value according to the logic
// described on the [RequestTestCase.ContainsData] property.
func assertContains(t *testing.T, contains map[string]any, actual map[string]any) {
func assertContains(t testing.TB, contains map[string]any, actual map[string]any) {
for k, expected := range contains {
innerActual := actual[k]
if innerExpected, innerIsMap := expected.(map[string]any); innerIsMap {
Expand Down Expand Up @@ -2005,7 +2005,7 @@ func assertContains(t *testing.T, contains map[string]any, actual map[string]any
}
}

func assertBackupContent(t *testing.T, expectedContent, filepath string) {
func assertBackupContent(t testing.TB, expectedContent, filepath string) {
b, err := os.ReadFile(filepath)
assert.NoError(t, err)
assert.Equal(
Expand All @@ -2017,7 +2017,7 @@ func assertBackupContent(t *testing.T, expectedContent, filepath string) {

// skipIfMutationTypeUnsupported skips the current test if the given supportedMutationTypes option has value
// and the active mutation type is not contained within that value set.
func skipIfMutationTypeUnsupported(t *testing.T, supportedMutationTypes immutable.Option[[]MutationType]) {
func skipIfMutationTypeUnsupported(t testing.TB, supportedMutationTypes immutable.Option[[]MutationType]) {
if supportedMutationTypes.HasValue() {
var isTypeSupported bool
for _, supportedMutationType := range supportedMutationTypes.Value() {
Expand All @@ -2038,7 +2038,7 @@ func skipIfMutationTypeUnsupported(t *testing.T, supportedMutationTypes immutabl
// If supportedClientTypes is none no filtering will take place and the input client set will be returned.
// If the resultant filtered set is empty the test will be skipped.
func skipIfClientTypeUnsupported(
t *testing.T,
t testing.TB,
clients []ClientType,
supportedClientTypes immutable.Option[[]ClientType],
) []ClientType {
Expand All @@ -2065,7 +2065,7 @@ func skipIfClientTypeUnsupported(

// skipIfNetworkTest skips the current test if the given actions
// contain network actions and skipNetworkTests is true.
func skipIfNetworkTest(t *testing.T, actions []any) {
func skipIfNetworkTest(t testing.TB, actions []any) {
hasNetworkAction := false
for _, act := range actions {
switch act.(type) {
Expand Down

0 comments on commit e3eca29

Please sign in to comment.