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)
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package extras
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
insights "github.com/hanzoai/insights-go"
|
|
)
|
|
|
|
// timeoutTransport wraps an http.RoundTripper with a timeout.
|
|
type timeoutTransport struct {
|
|
rt http.RoundTripper
|
|
timeout time.Duration
|
|
}
|
|
|
|
func (t *timeoutTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
ctx, cancel := context.WithTimeout(req.Context(), t.timeout)
|
|
defer cancel()
|
|
return t.rt.RoundTrip(req.WithContext(ctx))
|
|
}
|
|
|
|
// testCallback implements insights.Callback to track success/failure in tests.
|
|
type testCallback struct {
|
|
t *testing.T
|
|
mu sync.Mutex
|
|
successCount int
|
|
failureCount int
|
|
lastError error
|
|
successChan chan insights.APIMessage
|
|
failureChan chan error
|
|
}
|
|
|
|
func newTestCallback(t *testing.T) *testCallback {
|
|
return &testCallback{
|
|
t: t,
|
|
successChan: make(chan insights.APIMessage, 100),
|
|
failureChan: make(chan error, 100),
|
|
}
|
|
}
|
|
|
|
func (c *testCallback) Success(msg insights.APIMessage) {
|
|
c.mu.Lock()
|
|
c.successCount++
|
|
c.mu.Unlock()
|
|
c.t.Logf("Callback: SUCCESS")
|
|
c.successChan <- msg
|
|
}
|
|
|
|
func (c *testCallback) Failure(msg insights.APIMessage, err error) {
|
|
c.mu.Lock()
|
|
c.failureCount++
|
|
c.lastError = err
|
|
c.mu.Unlock()
|
|
c.t.Logf("Callback: FAILURE - %v", err)
|
|
c.failureChan <- err
|
|
}
|
|
|
|
func (c *testCallback) GetCounts() (success, failure int) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
return c.successCount, c.failureCount
|
|
}
|