helpers

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFileContains

func AssertFileContains(t *testing.T, path, content string)

AssertFileContains checks if a file contains a specific string

func CaptureOutput

func CaptureOutput(_ *testing.T, fn func()) (stdout, stderr string)

CaptureOutput captures stdout and stderr

func CompareJSON

func CompareJSON(t *testing.T, expected, actual string)

CompareJSON compares two JSON strings

func CreateTestEnvFile

func CreateTestEnvFile(t *testing.T, path string, vars map[string]string)

CreateTestEnvFile creates a test .env file

func CreateTestServer

func CreateTestServer(_ *testing.T, routes map[string]http.Handler) *httptest.Server

CreateTestServer creates a test HTTP server with predefined routes

func LoadFixture

func LoadFixture(t *testing.T, name string) []byte

LoadFixture loads a fixture file

func SetEnv

func SetEnv(t *testing.T, vars map[string]string)

SetEnv sets environment variables and cleans up after test

func WriteFixture

func WriteFixture(t *testing.T, path, content string)

WriteFixture writes a fixture file

Types

type MockResponse

type MockResponse struct {
	Status  int
	Body    interface{}
	Headers map[string]string
}

MockResponse creates a mock HTTP response

func (MockResponse) ServeHTTP

func (m MockResponse) ServeHTTP(w http.ResponseWriter, _ *http.Request)

ServeHTTP implements http.Handler

type TestConfig

type TestConfig struct {
	TempDir    string
	ConfigPath string
	Server     *httptest.Server
	APIKey     string
}

TestConfig holds test configuration

func NewTestConfig

func NewTestConfig(t testing.TB) *TestConfig

NewTestConfig creates a new test configuration.

Sets DOTENV_CONFIG_DIR + HOME to fresh temp paths so the CLI under test cannot leak into the developer's real ~/.dotenv account store (which would otherwise trigger OAuth refresh against a real API and hit rate limits).

Layout: tempDir/ (HOME) -> .dotenv/ (DOTENV_CONFIG_DIR via UserHomeDir) -> config.yaml. This matches the production layout config.ConfigPath() returns.

func (*TestConfig) RedirectUI

func (tc *TestConfig) RedirectUI(t *testing.T, stdout, stderr *bytes.Buffer)

RedirectUI swaps ui.Stdout / ui.Stderr to the supplied buffers for the lifetime of the test. Tests that assert on Print*-produced text need this because cobra's SetOut/SetErr only captures cobra's own writes.

func (*TestConfig) WriteConfig

func (tc *TestConfig) WriteConfig(t testing.TB, cfg interface{})

WriteConfig writes a test configuration file.

Legacy compatibility: if the supplied config carries the old `contexts` shape, this method translates the first context into the new accounts/ account_manager format via the production AccountManager so the CLI under test can authenticate. Tests written for the modern shape pass through unchanged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL