Documentation
¶
Overview ¶
Package testutil hosts in-memory test fakes for the production ports defined in github.com/algo2go/kite-mcp-clockport. Production code does NOT import testutil; only _test.go files do.
FakeClock + fakeTicker provide a deterministic implementation of clockport.Clock + clockport.Ticker that advances only when Advance() is called. This lets rate-limit / scheduler-style goroutines be driven forward without wall-clock waits.
The matching production port + RealClock implementation live at github.com/algo2go/kite-mcp-clockport (Path A.27, 28th algo2go module). The split is documented at .research/testutil-clock-port-split-design.md (commit fa6c70a) and .research/path-a-27-clockport-pick.md (this commit).
What this fake does NOT help with:
- Sleeps that wait for external I/O (TCP bind, HTTP server readiness, SQLite worker drain). A fake clock cannot make the OS bind faster; those sleeps stay and belong to integration-test scope.
Package testutil provides shared test infrastructure for the kite-mcp-server project. It is NOT a _test.go file so that any package can import it.
Index ¶
- func CaptureLogger() *logport.CaptureLogger
- func DiscardLogger() *slog.Logger
- func NewSessionKiteServer(t *testing.T) *httptest.Server
- func NoopLogger() logport.Logger
- type FakeClock
- type MockKiteServer
- func (m *MockKiteServer) Client(apiKey, accessToken string) *kiteconnect.Client
- func (m *MockKiteServer) SetBasketMargins(v any)
- func (m *MockKiteServer) SetHoldings(v any)
- func (m *MockKiteServer) SetMFHoldings(v any)
- func (m *MockKiteServer) SetMFOrders(v any)
- func (m *MockKiteServer) SetMFSIPs(v any)
- func (m *MockKiteServer) SetMargins(v any)
- func (m *MockKiteServer) SetOrderMargins(v any)
- func (m *MockKiteServer) SetOrders(v any)
- func (m *MockKiteServer) SetPositions(v any)
- func (m *MockKiteServer) SetProfile(v any)
- func (m *MockKiteServer) SetQuotes(v any)
- func (m *MockKiteServer) SetTrades(v any)
- func (m *MockKiteServer) SetTriggerRange(v any)
- func (m *MockKiteServer) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureLogger ¶
func CaptureLogger() *logport.CaptureLogger
CaptureLogger returns a fresh kc/logger.CaptureLogger so a test can assert "logger received X" without piping through io.Discard + regex matching. The returned value is both the *CaptureLogger (with a Records() method) and a Logger — the test can pass it into the system under test and read back observed records afterwards.
func DiscardLogger ¶
DiscardLogger returns a slog.Logger that discards all output. It is the canonical no-op logger used by every package's test suite, so tests can converge on a single fixture instead of re-building their own.
func NewSessionKiteServer ¶
NewSessionKiteServer returns a bare *httptest.Server that handles the Kite session lifecycle routes (POST /session/token, GET /user/profile, DELETE /session/token) plus all default MockKiteServer data routes. It is the shared replacement for per-package newMockKiteServer helpers that test the GenerateSession → CompleteSession → InvalidateAccessToken flow.
The server is automatically closed when the test finishes.
func NoopLogger ¶
NoopLogger returns the kc/logger.Logger port wired to a no-op implementation — the test-time companion to DiscardLogger for code that has been migrated to depend on the Logger port instead of the concrete *slog.Logger. Both fixtures coexist during the gradual migration: pick whichever matches the constructor signature you're testing.
Types ¶
type FakeClock ¶
type FakeClock struct {
// contains filtered or unexported fields
}
FakeClock is a test clock whose time only moves when Advance is called. All Tickers registered via NewTicker observe the advances atomically.
FakeClock is safe for concurrent use. Ticker channels are buffered (1) so an Advance that crosses multiple tick boundaries delivers one tick per boundary without blocking; if the caller has not drained the channel, subsequent ticks across the same boundary coalesce (matching the stdlib time.Ticker semantics).
func NewFakeClock ¶
NewFakeClock returns a FakeClock initialised to the given time. Pass time.Now() if the absolute value is irrelevant.
func (*FakeClock) Advance ¶
Advance moves the fake clock forward by d, delivering ticks for every registered ticker whose `next` boundary the advance crosses. Returns the count of ticks delivered across all tickers.
type MockKiteServer ¶
MockKiteServer wraps an httptest.Server that simulates the Kite Connect API. Tests configure responses via the Set* methods and then point a kiteconnect.Client at Server.URL.
IMPORTANT: The gokiteconnect SDK routes GetLTP(), GetOHLC(), and GetQuotes() all through the /quote endpoint (not /quote/ltp or /quote/ohlc). This mock handles /quote as the primary route. The /quote/ltp and /quote/ohlc paths are registered as aliases for direct HTTP testing convenience.
func NewMockKiteServer ¶
func NewMockKiteServer(t *testing.T) *MockKiteServer
NewMockKiteServer creates a mock Kite HTTP server with realistic default responses for all required endpoints. The server is automatically closed when the test finishes.
func (*MockKiteServer) Client ¶
func (m *MockKiteServer) Client(apiKey, accessToken string) *kiteconnect.Client
Client creates a kiteconnect.Client pointed at this mock server.
func (*MockKiteServer) SetBasketMargins ¶
func (m *MockKiteServer) SetBasketMargins(v any)
func (*MockKiteServer) SetHoldings ¶
func (m *MockKiteServer) SetHoldings(v any)
func (*MockKiteServer) SetMFHoldings ¶
func (m *MockKiteServer) SetMFHoldings(v any)
func (*MockKiteServer) SetMFOrders ¶
func (m *MockKiteServer) SetMFOrders(v any)
func (*MockKiteServer) SetMFSIPs ¶
func (m *MockKiteServer) SetMFSIPs(v any)
func (*MockKiteServer) SetMargins ¶
func (m *MockKiteServer) SetMargins(v any)
func (*MockKiteServer) SetOrderMargins ¶
func (m *MockKiteServer) SetOrderMargins(v any)
func (*MockKiteServer) SetOrders ¶
func (m *MockKiteServer) SetOrders(v any)
func (*MockKiteServer) SetPositions ¶
func (m *MockKiteServer) SetPositions(v any)
func (*MockKiteServer) SetProfile ¶
func (m *MockKiteServer) SetProfile(v any)
func (*MockKiteServer) SetQuotes ¶
func (m *MockKiteServer) SetQuotes(v any)
func (*MockKiteServer) SetTrades ¶
func (m *MockKiteServer) SetTrades(v any)
func (*MockKiteServer) SetTriggerRange ¶
func (m *MockKiteServer) SetTriggerRange(v any)
func (*MockKiteServer) URL ¶
func (m *MockKiteServer) URL() string
URL returns the base URL of the mock server.