Files
zeekayandHanzo Dev 8ee8950230 Go 1.27.1, and the code it can say more simply
The module declares go 1.27.1 and the adapter image follows. go fix
applied the modernizers and left ptrString and ptrBool with no callers,
so they are gone; omitzero is not applied, since it changes what the
JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:52:31 -07:00

59 lines
1.4 KiB
Go

package insights
import (
"bytes"
"errors"
"log"
"testing"
)
type loggerFromTest testing.T
func (l *loggerFromTest) Debugf(format string, args ...any) {
(*testing.T)(l).Logf(format, args...)
}
func (l *loggerFromTest) Logf(format string, args ...any) {
(*testing.T)(l).Logf(format, args...)
}
func (l *loggerFromTest) Warnf(format string, args ...any) {
(*testing.T)(l).Logf(format, args...)
}
func (l *loggerFromTest) Errorf(format string, args ...any) {
(*testing.T)(l).Errorf(format, args...)
}
func toLogger(t *testing.T) Logger {
return Logger((*loggerFromTest)(t))
}
// This test ensures that the interface doesn't get changed and stays compatible
// with the *testing.T type.
// If someone were to modify the interface in backward incompatible manner this
// test would break.
func TestTestingLogger(t *testing.T) {
_ = Logger((*loggerFromTest)(t))
}
// This test ensures the standard logger shim to the Logger interface is working
// as expected.
func TestStdLogger(t *testing.T) {
var buffer bytes.Buffer
var logger = StdLogger(log.New(&buffer, "test ", 0), false)
logger.Logf("Hello World!")
logger.Logf("The answer is %d", 42)
logger.Errorf("%s", errors.New("something went wrong!"))
const ref = `test INFO: Hello World!
test INFO: The answer is 42
test ERROR: something went wrong!
`
if res := buffer.String(); ref != res {
t.Errorf("invalid logs from standard logger:\n- expected: %s\n- found: %s", ref, res)
}
}