testing.go 898 Bytes
Newer Older
1 2
package e2eutils

3 4 5 6 7 8
import (
	"context"
	"testing"
	"time"
)

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// TestingBase is an interface used for standard Go testing.
// This interface is used for unit tests, benchmarks, and fuzz tests and also emulated in Hive.
//
// The Go testing.TB interface does not allow extensions by embedding the interface, so we repeat it here.
type TestingBase interface {
	Cleanup(func())
	Error(args ...any)
	Errorf(format string, args ...any)
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Name() string
	Setenv(key, value string)
	Skip(args ...any)
	SkipNow()
	Skipf(format string, args ...any)
	Skipped() bool
	TempDir() string
32
	Parallel()
33
}
34 35 36 37 38 39

func TimeoutCtx(t *testing.T, timeout time.Duration) context.Context {
	ctx, cancel := context.WithCancel(context.Background())
	t.Cleanup(cancel)
	return ctx
}