mirror of
https://github.com/hanzoai/insights-go.git
synced 2026-09-30 22:46:12 +00:00
Rename Go package from posthog to insights across all 80+ files. Consumers now import as `insights "github.com/hanzoai/insights-go"` and use insights.Client, insights.Config, insights.Capture, etc. - Rename posthog.go -> insights.go, posthog_test.go -> insights_test.go - Update package declaration from posthog to insights in all .go files - Update SDKName from posthog-go to insights-go - Update DefaultEndpoint from app.posthog.com to insights.hanzo.ai - Update all FieldError/ConfigError type strings - Update User-Agent headers, log prefixes, comments, and docs - Update JSON test fixtures to match new SDK name - Update CLI, examples, extras, and sdk_compliance_adapter - Fix pre-existing go vet warnings (non-constant format strings)
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package insights
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"log"
|
|
"testing"
|
|
)
|
|
|
|
type loggerFromTest testing.T
|
|
|
|
func (l *loggerFromTest) Debugf(format string, args ...interface{}) {
|
|
(*testing.T)(l).Logf(format, args...)
|
|
}
|
|
|
|
func (l *loggerFromTest) Logf(format string, args ...interface{}) {
|
|
(*testing.T)(l).Logf(format, args...)
|
|
}
|
|
|
|
func (l *loggerFromTest) Warnf(format string, args ...interface{}) {
|
|
(*testing.T)(l).Logf(format, args...)
|
|
}
|
|
|
|
func (l *loggerFromTest) Errorf(format string, args ...interface{}) {
|
|
(*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)
|
|
}
|
|
}
|