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:
ashmrtn 2023-08-25 10:28:09 -07:00 committed by GitHub
parent e1fe7f4b16
commit bf29443ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 9 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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()

View File

@ -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
}{
{

View File

@ -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()