Documentation
¶
Index ¶
- func BuildCliLogger(pathElements []string, outputModeEnvVar string) *zap.SugaredLogger
- func BuildMockedCliLogger(pathElements []string, outputModeEnvVar string, mockTargets *MockTargets) *zap.SugaredLogger
- func ExecuteCliOutErr(ct *CliTestConfig) (string, string, error)
- func FilePathFromHomeDir(pathElementsRelativeToHome []string) (string, error)
- func NewCliEncoder(printedKey string) zapcore.Encoder
- type CliOutput
- type CliTestConfig
- type CommandConfig
- type MockTargets
- type MockWriteSyncer
- type RootCommandFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCliLogger ¶
func BuildCliLogger(pathElements []string, outputModeEnvVar string) *zap.SugaredLogger
BuildCliLogger creates a set of loggers for use in CLI applications. - A json-formatted file logger that writes all log messages to the specified filename - A human-friendly console logger that writes info and warning messages to stdout - A human-friendly console logger that writes info and warning messages to stderr
func BuildMockedCliLogger ¶
func BuildMockedCliLogger(pathElements []string, outputModeEnvVar string, mockTargets *MockTargets) *zap.SugaredLogger
BuildMockedCliLogger is the test-environment counterpart of BuildCliLogger It stores log output in buffers that can be inspected by tests.
func ExecuteCliOutErr ¶
func ExecuteCliOutErr(ct *CliTestConfig) (string, string, error)
ExecuteCliOutErr is a helper for calling a cobra command within a test
func FilePathFromHomeDir ¶
FilePathFromHomeDir is a utility that makes it easier to find the absolute path to a file, given its file path elements relative to its home directory. pathElementsRelativeToHome is passed as an array to avoid os-specific directory delimiter complications example: []string{".config","default.yaml"}
func NewCliEncoder ¶
Types ¶
type CliOutput ¶
type CliOutput struct {
LoggerConsoleStderr string
LoggerConsoleStout string
LoggerFileContent string
CobraStderr string
CobraStdout string
}
CliOutput captures all the relevant output from a Cobra Command For clarity and simplicity, output from zapcore loggers are stored separately otherwise, it would be necessary to coordinate the initialization of the loggers with the os.Std*** manipulation done in ExecuteCliOutErr
type CliTestConfig ¶
type CliTestConfig struct {
CommandConfig *CommandConfig
MockTargets *MockTargets
TestArgs string
// contains filtered or unexported fields
}
type CommandConfig ¶
type CommandConfig struct {
Args string
Command RootCommandFunc
CommandErrorHandler func(error)
RootErrorMessage string
OutputModeEnvVar string
LoggingContext []interface{}
FileLogPathElements []string
Version string
// contains filtered or unexported fields
}
func (CommandConfig) Run ¶
func (cc CommandConfig) Run()
func (*CommandConfig) RunForTest ¶
func (cc *CommandConfig) RunForTest(args string) (CliOutput, error)
type MockTargets ¶
type MockTargets struct {
Stdout *MockWriteSyncer
Stderr *MockWriteSyncer
FileLog *MockWriteSyncer
}
func NewMockTargets ¶
func NewMockTargets() MockTargets
type MockWriteSyncer ¶
type MockWriteSyncer struct {
// contains filtered or unexported fields
}
func (*MockWriteSyncer) Sync ¶
func (m *MockWriteSyncer) Sync() error