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 ¶
- func BuildCLIForTests(path string, subCmds []*cli.Command) *cli.Command
- func CaptureStdout(f func()) (string, error)
- func IsWindows() bool
- func ReadFile(t *testing.T, path string) string
- func ReadTempVersionFile(t *testing.T, dir string) string
- func RunCLITest(t *testing.T, appCli *cli.Command, args []string, workdir string)
- func RunCLITestAllowError(t *testing.T, appCli *cli.Command, args []string, workdir string) error
- func WithMock(setup func(), testFunc func())
- func WriteFile(t *testing.T, path, content string, perm fs.FileMode)
- func WriteTempConfig(t *testing.T, content string) string
- func WriteTempVersionFile(t *testing.T, dir, version string) string
- type MockCommitParser
- type MockHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureStdout ¶
CaptureStdout captures both stdout and stderr output produced during the execution of f.
func ReadTempVersionFile ¶
ReadTempVersionFile reads and returns the trimmed contents of the `.version` file in the given directory.
func RunCLITest ¶
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 ¶
RunCLITestAllowError runs a CLI command using the given args in the provided workdir, and returns any error instead of failing the test.
func WriteFile ¶
WriteFile writes content to a file with the given permissions and fails the test on error.
func WriteTempConfig ¶
WriteTempConfig writes a temporary `.sley.yaml` file with the given content and returns its path.
Types ¶
type MockCommitParser ¶
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) Version ¶
func (m MockCommitParser) Version() string