clitest

package
v0.1.34770 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package clitest contains common utilities and helpers for testing the CLI

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareTelemetryEvent added in v0.1.28363

func CompareTelemetryEvent(settings *TempSettings, expected []telemetry.Event)

CompareTelemetryEvent asserts that the recorded telemetry events exactly match `expected`. Use this when you need strict ordering and field equality.

func CompareTelemetryEventSubset added in v0.1.34770

func CompareTelemetryEventSubset(settings *TempSettings, expected []telemetry.Event)

CompareTelemetryEventSubset asserts that every event in `expected` appears somewhere in the recorded events. Use this when the middleware also emits cli_command_started / cli_command_finished events alongside legacy events and you only want to verify the legacy event payload.

func ReadTelemetryEvents added in v0.1.34770

func ReadTelemetryEvents(settings *TempSettings) []telemetry.Event

ReadTelemetryEvents reads and parses all telemetry events from the mock file.

func ShouldFail added in v0.1.7868

func ShouldFail() types.GomegaMatcher

On Unix, we want to assert that processed exited with 255 On Windows, it should be -1.

func WithCapturedOutput

func WithCapturedOutput(f func()) string

WithCapturedOutput will call the provided function and capture any output to stdout which is returned as a string.

Types

type MockRequestResponse

type MockRequestResponse struct {
	Request       string
	Status        int
	Response      string
	ErrorResponse string
}

MockRequestResponse is a helpful type for mocking HTTP handlers.

type TempSettings

type TempSettings struct {
	Home              string
	TestServer        *ghttp.Server
	Config            *TmpFile
	Update            *TmpFile
	Telemetry         *TmpFile
	TelemetryDestPath string
}

TempSettings contains useful settings for testing the CLI

func WithTempSettings

func WithTempSettings() *TempSettings

WithTempSettings should be called in a BeforeEach and returns a new TempSettings with everything setup for you

func (*TempSettings) AppendPostHandler

func (tempSettings *TempSettings) AppendPostHandler(authToken string, combineHandlers ...MockRequestResponse)

AppendPostHandler stubs out the provided MockRequestResponse. When authToken is an empty string no token validation is performed.

func (TempSettings) AssertConfigRereadMatches

func (tempSettings TempSettings) AssertConfigRereadMatches(contents string)

AssertConfigRereadMatches re-opens the config file and checks it's contents against the given string

func (*TempSettings) Close added in v0.1.7868

func (settings *TempSettings) Close() error

Close should be called in an AfterEach and cleans up the temp directory and server process

func (*TempSettings) NewFakeClient

func (tempSettings *TempSettings) NewFakeClient(endpoint, token string) *graphql.Client

NewFakeClient returns a new *client.Client with the TestServer set and the provided endpoint, token.

type TmpFile

type TmpFile struct {
	RootDir string
	Path    string
	File    *os.File
}

TmpFile wraps a temporary file on disk for utility.

func OpenTmpFile

func OpenTmpFile(directory string, path string) *TmpFile

OpenTmpFile will create a new temporary file in the provided directory with a name of the given path.

func (*TmpFile) Close added in v0.1.7868

func (tempFile *TmpFile) Close() error

func (TmpFile) Write

func (f TmpFile) Write(contents []byte)

Write will write the given contents to the file on disk and close it.

Jump to

Keyboard shortcuts

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