Use interface for test helper functions (#4114)
Take an interface as the parameter for test helper functions. This allows them to be used with *testing.B (benchmark) as well as *testing.T (test). --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
e1fe7f4b16
commit
bf29443ad4
@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func openKopiaRepo(
|
||||
t *testing.T,
|
||||
t tester.TestT,
|
||||
ctx context.Context, //revive:disable-line:context-as-argument
|
||||
) (*conn, error) {
|
||||
st := storeTD.NewPrefixedS3Storage(t)
|
||||
|
||||
@ -3,7 +3,6 @@ package tester
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/alcionai/clues"
|
||||
"github.com/google/uuid"
|
||||
@ -11,7 +10,7 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/logger"
|
||||
)
|
||||
|
||||
func NewContext(t *testing.T) (context.Context, func()) {
|
||||
func NewContext(t TestT) (context.Context, func()) {
|
||||
level := logger.LLInfo
|
||||
format := logger.LFText
|
||||
|
||||
@ -34,7 +33,7 @@ func NewContext(t *testing.T) (context.Context, func()) {
|
||||
}
|
||||
|
||||
func WithContext(
|
||||
t *testing.T,
|
||||
t TestT,
|
||||
ctx context.Context, //revive:disable-line:context-as-argument
|
||||
) (context.Context, func()) {
|
||||
ls := logger.Settings{
|
||||
@ -48,7 +47,7 @@ func WithContext(
|
||||
}
|
||||
|
||||
func enrichTestCtx(
|
||||
t *testing.T,
|
||||
t TestT,
|
||||
ctx context.Context, //revive:disable-line:context-as-argument
|
||||
) context.Context {
|
||||
if t == nil {
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// AreSameFunc asserts whether the two funcs are the same func.
|
||||
@ -26,8 +27,15 @@ func AreSameFunc(t *testing.T, expect, have any) {
|
||||
)
|
||||
}
|
||||
|
||||
type TestT interface {
|
||||
Logf(format string, args ...any)
|
||||
Name() string
|
||||
TempDir() string
|
||||
require.TestingT
|
||||
}
|
||||
|
||||
// LogTimeOfTest logs the test name and the time that it was run.
|
||||
func LogTimeOfTest(t *testing.T) string {
|
||||
func LogTimeOfTest(t TestT) string {
|
||||
now := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
name := t.Name()
|
||||
|
||||
|
||||
@ -126,7 +126,7 @@ func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
||||
table := []struct {
|
||||
name string
|
||||
account account.Account
|
||||
storage func(*testing.T) storage.Storage
|
||||
storage func(tester.TestT) storage.Storage
|
||||
errCheck assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
|
||||
3
src/pkg/storage/testdata/storage.go
vendored
3
src/pkg/storage/testdata/storage.go
vendored
@ -2,7 +2,6 @@ package testdata
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/alcionai/clues"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -28,7 +27,7 @@ var AWSStorageCredEnvs = []string{
|
||||
// Uses t.TempDir() to generate a unique config storage and caching directory for this
|
||||
// test. Suites that need to identify this value can retrieve it again from the common
|
||||
// configs.
|
||||
func NewPrefixedS3Storage(t *testing.T) storage.Storage {
|
||||
func NewPrefixedS3Storage(t tester.TestT) storage.Storage {
|
||||
now := tester.LogTimeOfTest(t)
|
||||
|
||||
cfg, err := tconfig.ReadTestConfig()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user