clitest

package
v2.24.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UpdateGoldenFiles = flag.Bool("update", false, "update .golden files")

UpdateGoldenFiles indicates golden files should be updated. To update the golden files: make gen/golden-files

Functions

func CreateTemplateVersionSource

func CreateTemplateVersionSource(t *testing.T, responses *echo.Responses) string

CreateTemplateVersionSource writes the echo provisioner responses into a new temporary testing directory.

func HandlersOK

func HandlersOK(t *testing.T, cmd *serpent.Command)

HandlersOK asserts that all commands have a handler. Without a handler, the command has no default behavior. Even for non-root commands (like 'groups' or 'users'), a handler is required. These handlers are likely just the 'help' handler, but this must be explicitly set.

func New

func New(t testing.TB, args ...string) (*serpent.Invocation, config.Root)

New creates a CLI instance with a configuration pointed to a temporary testing directory.

func NewWithCommand

func NewWithCommand(
	t testing.TB, cmd *serpent.Command, args ...string,
) (*serpent.Invocation, config.Root)

func Run

func Run(t *testing.T, inv *serpent.Invocation)

Run runs the command and asserts that there is no error.

func SetupConfig

func SetupConfig(t *testing.T, client *codersdk.Client, root config.Root)

SetupConfig applies the URL and SessionToken of the client to the config.

func Start

func Start(t *testing.T, inv *serpent.Invocation)

Start runs the command in a goroutine and cleans it up when the test completed.

func StartWithAssert added in v2.9.0

func StartWithAssert(t *testing.T, inv *serpent.Invocation, assertCallback func(t *testing.T, err error))

func TestCommandHelp

func TestCommandHelp(t *testing.T, getRoot func(t *testing.T) *serpent.Command, cases []CommandHelpCase)

TestCommandHelp will test the help output of the given commands using golden files.

func TestGoldenFile added in v2.10.0

func TestGoldenFile(t *testing.T, fileName string, actual []byte, replacements map[string]string)

TestGoldenFile will test the given bytes slice input against the golden file with the given file name, optionally using the given replacements.

Types

type CommandHelpCase

type CommandHelpCase struct {
	Name string
	Cmd  []string
}

func DefaultCases

func DefaultCases() []CommandHelpCase

type ErrorWaiter

type ErrorWaiter struct {
	// contains filtered or unexported fields
}

func StartWithWaiter

func StartWithWaiter(t *testing.T, inv *serpent.Invocation) *ErrorWaiter

StartWithWaiter runs the command in a goroutine but returns the error instead of asserting it. This is useful for testing error cases.

func (*ErrorWaiter) Cancel

func (w *ErrorWaiter) Cancel()

func (*ErrorWaiter) RequireAs

func (w *ErrorWaiter) RequireAs(want interface{})

func (*ErrorWaiter) RequireContains

func (w *ErrorWaiter) RequireContains(s string)

func (*ErrorWaiter) RequireError

func (w *ErrorWaiter) RequireError()

func (*ErrorWaiter) RequireIs

func (w *ErrorWaiter) RequireIs(want error)

func (*ErrorWaiter) RequireSuccess

func (w *ErrorWaiter) RequireSuccess()

func (*ErrorWaiter) Wait

func (w *ErrorWaiter) Wait() error

type FakeSignalNotifier added in v2.4.0

type FakeSignalNotifier struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFakeSignalNotifier added in v2.4.0

func NewFakeSignalNotifier(t *testing.T) *FakeSignalNotifier

func (*FakeSignalNotifier) AssertStopped added in v2.4.0

func (f *FakeSignalNotifier) AssertStopped()

func (*FakeSignalNotifier) Notify added in v2.4.0

func (f *FakeSignalNotifier) Notify()

func (*FakeSignalNotifier) NotifyContext added in v2.4.0

func (f *FakeSignalNotifier) NotifyContext(parent context.Context, signals ...os.Signal) (ctx context.Context, stop context.CancelFunc)

func (*FakeSignalNotifier) Stop added in v2.4.0

func (f *FakeSignalNotifier) Stop()

Jump to

Keyboard shortcuts

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

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy