testutils

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package testutils provides helper functions for testing CLI applications. It includes utilities for reading/writing temp files, capturing CLI output, and running CLI commands in isolated working directories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCLIForTests

func BuildCLIForTests(path string, subCmds []*cli.Command) *cli.Command

func CaptureStdout

func CaptureStdout(f func()) (string, error)

CaptureStdout captures both stdout and stderr output produced during the execution of f.

func IsWindows

func IsWindows() bool

IsWindows returns true if the current OS is Windows.

func ReadFile

func ReadFile(t *testing.T, path string) string

ReadFile reads the contents of a file and fails the test on error.

func ReadTempVersionFile

func ReadTempVersionFile(t *testing.T, dir string) string

ReadTempVersionFile reads and returns the trimmed contents of the `.version` file in the given directory.

func RunCLITest

func RunCLITest(t *testing.T, appCli *cli.Command, args []string, workdir string)

RunCLITest runs a CLI command using the given args in the provided workdir, and fails the test if the command returns an error.

func RunCLITestAllowError

func RunCLITestAllowError(t *testing.T, appCli *cli.Command, args []string, workdir string) error

RunCLITestAllowError runs a CLI command using the given args in the provided workdir, and returns any error instead of failing the test.

func WithMock

func WithMock(setup func(), testFunc func())

func WriteFile

func WriteFile(t *testing.T, path, content string, perm fs.FileMode)

WriteFile writes content to a file with the given permissions and fails the test on error.

func WriteTempConfig

func WriteTempConfig(t *testing.T, content string) string

WriteTempConfig writes a temporary `.sley.yaml` file with the given content and returns its path.

func WriteTempVersionFile

func WriteTempVersionFile(t *testing.T, dir, version string) string

WriteTempVersionFile writes a `.version` file with the given content and returns its path.

Types

type MockCommitParser

type MockCommitParser struct {
	Label string
	Err   error
}

MockCommitParser implements the plugins.CommitParser interface for testing.

func (MockCommitParser) Description

func (m MockCommitParser) Description() string

func (MockCommitParser) Name

func (m MockCommitParser) Name() string

func (MockCommitParser) Parse

func (m MockCommitParser) Parse(_ []string) (string, error)

func (MockCommitParser) Version

func (m MockCommitParser) Version() string

type MockHook

type MockHook struct {
	Name      string
	ShouldErr bool
}

MockHook implements PreReleaseHook for testing

func (MockHook) HookName

func (m MockHook) HookName() string

func (MockHook) Run

func (m MockHook) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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