Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
772 B

package testutil
import (
"fmt"
"io"
"log"
"os"
"strings"
"testing"
)
var sendTestLogsToStdout bool
func init() {
sendTestLogsToStdout = os.Getenv("NOLOGBUFFER") == "1"
}
func TestLogger(t testing.TB) *log.Logger {
return log.New(&testWriter{t}, t.Name()+": ", log.LstdFlags)
}
func TestLoggerWithName(t testing.TB, name string) *log.Logger {
return log.New(&testWriter{t}, "test["+name+"]: ", log.LstdFlags)
}
func TestWriter(t testing.TB) io.Writer {
return &testWriter{t}
}
type testWriter struct {
t testing.TB
}
func (tw *testWriter) Write(p []byte) (n int, err error) {
tw.t.Helper()
if sendTestLogsToStdout {
fmt.Fprint(os.Stdout, strings.TrimSpace(string(p))+"\n")
} else {
tw.t.Log(strings.TrimSpace(string(p)))
}
return len(p), nil
}