2024-10-06 15:15:40 +00:00
|
|
|
package toolkit
|
|
|
|
|
|
|
|
import (
|
2024-10-29 14:11:13 +00:00
|
|
|
"fmt"
|
2024-10-06 15:15:40 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
2024-10-29 14:11:13 +00:00
|
|
|
|
|
|
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
2024-11-11 14:32:15 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
2024-10-06 15:15:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MarkIntegrationTest marks a test as being an integration test. It will be
|
|
|
|
// skipped if the ISLE_INTEGRATION_TEST envvar isn't set.
|
|
|
|
func MarkIntegrationTest(t *testing.T) {
|
|
|
|
if os.Getenv("ISLE_INTEGRATION_TEST") == "" {
|
|
|
|
t.Skip("Skipped because ISLE_INTEGRATION_TEST isn't set")
|
|
|
|
}
|
|
|
|
}
|
2024-10-29 14:11:13 +00:00
|
|
|
|
|
|
|
// NewTestLogger returns a Logger which should be used for testing purposes. The
|
|
|
|
// log level of the Logger can be adjusted using the ISLE_LOG_LEVEL envvar.
|
|
|
|
func NewTestLogger(t *testing.T) *mlog.Logger {
|
|
|
|
level := mlog.LevelInfo
|
|
|
|
if levelStr := os.Getenv("ISLE_LOG_LEVEL"); levelStr != "" {
|
|
|
|
if level = LogLevelFromString(levelStr); level == nil {
|
|
|
|
panic(fmt.Sprintf("invalid log level: %q", levelStr))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mlog.NewLogger(&mlog.LoggerOpts{
|
|
|
|
MessageHandler: mlog.NewTestMessageHandler(t),
|
|
|
|
MaxLevel: level.Int(),
|
|
|
|
})
|
|
|
|
}
|
2024-11-11 14:32:15 +00:00
|
|
|
|
|
|
|
// MockArg returns a value which can be used as a [mock.Call] argument, and
|
|
|
|
// which will match any value of type T. If T is an interface then also values
|
|
|
|
// implementing that interface will be matched.
|
|
|
|
func MockArg[T any]() any {
|
|
|
|
return mock.MatchedBy(func(T) bool { return true })
|
|
|
|
}
|