Skip to content

Commit

Permalink
test: improve skip helpers
Browse files Browse the repository at this point in the history
Make skip helpers public. Add more wrappers to reduce code duplication.

Part of #215
  • Loading branch information
DifferentialOrange committed Dec 14, 2022
1 parent 3564714 commit 3a1e82b
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions test_helpers/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test_helpers

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -75,7 +76,8 @@ func SkipIfSQLUnsupported(t testing.TB) {
}
}

func skipIfLess(t *testing.T, feature string, major, minor, patch uint64) {
// SkipIfLess skips test run if Tarantool version is less than expected.
func SkipIfLess(t *testing.T, reason string, major, minor, patch uint64) {
t.Helper()

isLess, err := IsTarantoolVersionLess(major, minor, patch)
Expand All @@ -84,11 +86,13 @@ func skipIfLess(t *testing.T, feature string, major, minor, patch uint64) {
}

if isLess {
t.Skipf("Skipping test for Tarantool without %s support", feature)
t.Skipf("Skipping test for Tarantool %s", reason)
}
}

func skipIfGreaterOrEqual(t *testing.T, feature string, major, minor, patch uint64) {
// SkipIfGreaterOrEqual skips test run if Tarantool version is greater or equal
// than expected.
func SkipIfGreaterOrEqual(t *testing.T, reason string, major, minor, patch uint64) {
t.Helper()

isLess, err := IsTarantoolVersionLess(major, minor, patch)
Expand All @@ -97,40 +101,64 @@ func skipIfGreaterOrEqual(t *testing.T, feature string, major, minor, patch uint
}

if !isLess {
t.Skipf("Skipping test for Tarantool with %s support", feature)
t.Skipf("Skipping test for Tarantool %s", reason)
}
}

// SkipIfFeatureUnsupported skips test run if Tarantool does not yet support a feature.
func SkipIfFeatureUnsupported(t *testing.T, feature string, major, minor, patch uint64) {
t.Helper()

SkipIfLess(t, fmt.Sprintf("without %s support", feature), major, minor, patch)
}

// SkipIfFeatureSupported skips test run if Tarantool supports a feature.
// Helper if useful when we want to test if everything is alright
// on older versions.
func SkipIfFeatureSupported(t *testing.T, feature string, major, minor, patch uint64) {
t.Helper()

SkipIfGreaterOrEqual(t, fmt.Sprintf("with %s support", feature), major, minor, patch)
}

// SkipIfFeatureDropped skips test run if Tarantool had dropped
// support of a feature.
func SkipIfFeatureDropped(t *testing.T, feature string, major, minor, patch uint64) {
t.Helper()

SkipIfGreaterOrEqual(t, fmt.Sprintf("with %s support dropped", feature), major, minor, patch)
}

// SkipOfStreamsUnsupported skips test run if Tarantool without streams
// support is used.
func SkipIfStreamsUnsupported(t *testing.T) {
t.Helper()

skipIfLess(t, "streams", 2, 10, 0)
SkipIfFeatureUnsupported(t, "streams", 2, 10, 0)
}

// SkipOfStreamsUnsupported skips test run if Tarantool without watchers
// support is used.
func SkipIfWatchersUnsupported(t *testing.T) {
t.Helper()

skipIfLess(t, "watchers", 2, 10, 0)
SkipIfFeatureUnsupported(t, "watchers", 2, 10, 0)
}

// SkipIfWatchersSupported skips test run if Tarantool with watchers
// support is used.
func SkipIfWatchersSupported(t *testing.T) {
t.Helper()

skipIfGreaterOrEqual(t, "watchers", 2, 10, 0)
SkipIfFeatureSupported(t, "watchers", 2, 10, 0)
}

// SkipIfIdUnsupported skips test run if Tarantool without
// IPROTO_ID support is used.
func SkipIfIdUnsupported(t *testing.T) {
t.Helper()

skipIfLess(t, "id requests", 2, 10, 0)
SkipIfFeatureUnsupported(t, "id requests", 2, 10, 0)
}

// SkipIfIdSupported skips test run if Tarantool with
Expand All @@ -139,23 +167,23 @@ func SkipIfIdUnsupported(t *testing.T) {
func SkipIfIdSupported(t *testing.T) {
t.Helper()

skipIfGreaterOrEqual(t, "id requests", 2, 10, 0)
SkipIfFeatureSupported(t, "id requests", 2, 10, 0)
}

// SkipIfErrorExtendedInfoUnsupported skips test run if Tarantool without
// IPROTO_ERROR (0x52) support is used.
func SkipIfErrorExtendedInfoUnsupported(t *testing.T) {
t.Helper()

skipIfLess(t, "error extended info", 2, 4, 1)
SkipIfFeatureUnsupported(t, "error extended info", 2, 4, 1)
}

// SkipIfErrorMessagePackTypeUnsupported skips test run if Tarantool without
// MP_ERROR type over iproto support is used.
func SkipIfErrorMessagePackTypeUnsupported(t *testing.T) {
t.Helper()

skipIfLess(t, "error type in MessagePack", 2, 10, 0)
SkipIfFeatureUnsupported(t, "error type in MessagePack", 2, 10, 0)
}

// CheckEqualBoxErrors checks equivalence of tarantool.BoxError objects.
Expand Down

0 comments on commit 3a1e82b

Please sign in to comment.