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(
|
func openKopiaRepo(
|
||||||
t *testing.T,
|
t tester.TestT,
|
||||||
ctx context.Context, //revive:disable-line:context-as-argument
|
ctx context.Context, //revive:disable-line:context-as-argument
|
||||||
) (*conn, error) {
|
) (*conn, error) {
|
||||||
st := storeTD.NewPrefixedS3Storage(t)
|
st := storeTD.NewPrefixedS3Storage(t)
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package tester
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -11,7 +10,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"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
|
level := logger.LLInfo
|
||||||
format := logger.LFText
|
format := logger.LFText
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ func NewContext(t *testing.T) (context.Context, func()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WithContext(
|
func WithContext(
|
||||||
t *testing.T,
|
t TestT,
|
||||||
ctx context.Context, //revive:disable-line:context-as-argument
|
ctx context.Context, //revive:disable-line:context-as-argument
|
||||||
) (context.Context, func()) {
|
) (context.Context, func()) {
|
||||||
ls := logger.Settings{
|
ls := logger.Settings{
|
||||||
@ -48,7 +47,7 @@ func WithContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func enrichTestCtx(
|
func enrichTestCtx(
|
||||||
t *testing.T,
|
t TestT,
|
||||||
ctx context.Context, //revive:disable-line:context-as-argument
|
ctx context.Context, //revive:disable-line:context-as-argument
|
||||||
) context.Context {
|
) context.Context {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AreSameFunc asserts whether the two funcs are the same func.
|
// 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.
|
// 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)
|
now := time.Now().UTC().Format(time.RFC3339Nano)
|
||||||
name := t.Name()
|
name := t.Name()
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
|||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
account account.Account
|
account account.Account
|
||||||
storage func(*testing.T) storage.Storage
|
storage func(tester.TestT) storage.Storage
|
||||||
errCheck assert.ErrorAssertionFunc
|
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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/stretchr/testify/require"
|
"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
|
// 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
|
// test. Suites that need to identify this value can retrieve it again from the common
|
||||||
// configs.
|
// configs.
|
||||||
func NewPrefixedS3Storage(t *testing.T) storage.Storage {
|
func NewPrefixedS3Storage(t tester.TestT) storage.Storage {
|
||||||
now := tester.LogTimeOfTest(t)
|
now := tester.LogTimeOfTest(t)
|
||||||
|
|
||||||
cfg, err := tconfig.ReadTestConfig()
|
cfg, err := tconfig.ReadTestConfig()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user