testutils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureStdout added in v0.3.0

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

CaptureStdout captures all writes to os.Stdout and os.Stderr during the execution of the provided function. It returns the combined captured output as a string and restores os.Stdout and os.Stderr to their original states.

func Contains

func Contains(str, substr string) bool

Helper function to check if a string contains another string

func ContainsBetweenMarkers

func ContainsBetweenMarkers(content, expected string) bool

Helper to check if content exists between guard markers

func CreateFile

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

Helper to create files

func CreateModFile

func CreateModFile(tempDir string) error

func GenerateTemplContent

func GenerateTemplContent(packageName string) string

Helper to generate templ files with guard markers

func PrepareTestConfig

func PrepareTestConfig(cfg *config.Config, tempDir string)

func SetupComponentDefine

func SetupComponentDefine(app *cli.Command, t *testing.T) (string, error)

func SetupConfig

func SetupConfig(tempDir string, overrides func(cfg *config.Config)) *config.Config

func SetupVariantDefine

func SetupVariantDefine(app *cli.Command, t *testing.T) (string, error)

func ValidateCLIOutput added in v0.3.0

func ValidateCLIOutput(t *testing.T, output string, expectedMessages []string)

ValidateCLIOutput checks that all expectedMessages are present in the output string.

func ValidateGeneratedFiles

func ValidateGeneratedFiles(t *testing.T, paths []string)

ValidateGeneratedFiles ensures the specified files exist.

func VerifyFileContent

func VerifyFileContent(t *testing.T, filePath, expectedContent string)

Helper to verify if content was inserted correctly

func WriteConfigToFile

func WriteConfigToFile(filePath string, cfg *config.Config) error

WriteConfigToFile saves the configuration to the specified file path in YAML format.

Types

type MockLogger

type MockLogger struct {
	Logs []string
	// contains filtered or unexported fields
}

MockLogger is a mock implementation of the Logger interface for testing purposes.

func (*MockLogger) Blank

func (m *MockLogger) Blank()

Blank prints a blank line.

func (*MockLogger) Default

func (m *MockLogger) Default(message string, args ...any) *logger.LogEntry

Default logs a default message.

func (*MockLogger) Error

func (m *MockLogger) Error(message string, args ...any) *logger.LogEntry

Error logs an error message.

func (*MockLogger) Hint

func (m *MockLogger) Hint(message string, args ...any) *logger.LogEntry

Hint logs a hint message.

func (*MockLogger) Info

func (m *MockLogger) Info(message string, args ...any) *logger.LogEntry

Info logs an informational message.

func (*MockLogger) Reset

func (m *MockLogger) Reset()

Reset clears all stored log messages.

func (*MockLogger) Success

func (m *MockLogger) Success(message string, args ...any) *logger.LogEntry

Success logs a success message.

func (*MockLogger) Warning

func (m *MockLogger) Warning(message string, args ...any) *logger.LogEntry

Warning logs a warning message.

func (*MockLogger) WithIndent

func (m *MockLogger) WithIndent(enabled bool)

WithIndent enables or disables indentation for log messages.

func (*MockLogger) WithTimestamp

func (m *MockLogger) WithTimestamp(enabled bool)

WithTimestamp enables or disables the inclusion of timestamps in log messages.

Jump to

Keyboard shortcuts

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