isle/go/toolkit/testutils.go

34 lines
936 B
Go

package toolkit
import (
"fmt"
"os"
"testing"
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
)
// 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")
}
}
// 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(),
})
}