Documentation
¶
Index ¶
- Variables
- func MustParseFlags(fs *flag.FlagSet, args []string)
- func NewTestFlagSet(name string, flags map[string]interface{}) (*flag.FlagSet, error)
- func ParseFlags(fs *flag.FlagSet, args []string) error
- func RunConfigTests(t *testing.T, cases []ConfigTestCase, ...)
- type ConfigTestCase
- type EnvManager
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidEnvKey = fmt.Errorf("environment variable key cannot be empty or contain NUL")
ErrInvalidEnvKey is returned when an environment variable key is empty or invalid
Functions ¶
func MustParseFlags ¶
MustParseFlags parses command-line arguments and panics on error
Parameters:
- fs: FlagSet to parse
- args: Command-line arguments to parse
func NewTestFlagSet ¶
NewTestFlagSet creates a new FlagSet with predefined flags for testing
Parameters:
- name: Name of the FlagSet
- flags: Map of flag names to their default values and types Supported types: string, int, bool, float64
Returns:
- *flag.FlagSet: The created FlagSet
- error: Returns error if flag type is unsupported
func ParseFlags ¶
ParseFlags parses command-line arguments with a FlagSet
Parameters:
- fs: FlagSet to parse
- args: Command-line arguments to parse
Returns:
- error: Returns error if parsing fails
func RunConfigTests ¶
func RunConfigTests(t *testing.T, cases []ConfigTestCase, resolver func(*flag.FlagSet, map[string]string) (interface{}, error))
RunConfigTests runs a table-driven test for configuration resolution
Parameters:
- t: Testing.T instance
- cases: Test cases to run
- resolver: Function that resolves configuration and returns the result The resolver should set up FlagSet, parse CLI args, and resolve config
Types ¶
type ConfigTestCase ¶
type ConfigTestCase struct {
// Name is the test case name
Name string
// CLIArgs are command-line arguments to parse
CLIArgs []string
// EnvVars are environment variables to set
EnvVars map[string]string
// Expected is the expected configuration value
Expected interface{}
// WantErr indicates whether an error is expected
WantErr bool
}
ConfigTestCase represents a test case for configuration resolution
type EnvManager ¶
type EnvManager struct {
// contains filtered or unexported fields
}
EnvManager manages environment variables for testing It saves original values and can restore them after tests
func NewEnvManager ¶
func NewEnvManager() *EnvManager
NewEnvManager creates a new environment variable manager
func (*EnvManager) Cleanup ¶
func (m *EnvManager) Cleanup()
Cleanup is a convenience method for use with defer It restores all environment variables to their original values
func (*EnvManager) Clear ¶
func (m *EnvManager) Clear() error
Clear clears all managed environment variables (unsets them)
func (*EnvManager) Restore ¶
func (m *EnvManager) Restore() error
Restore restores all environment variables to their original values
func (*EnvManager) Set ¶
func (m *EnvManager) Set(key, value string) error
Set sets an environment variable and saves the original value
func (*EnvManager) SetMultiple ¶
func (m *EnvManager) SetMultiple(vars map[string]string) error
SetMultiple sets multiple environment variables at once
func (*EnvManager) Unset ¶
func (m *EnvManager) Unset(key string) error
Unset unsets an environment variable and saves the original value