1.9 KiB
1.9 KiB
Helmfile Test Command Package
Overview
The testcommand package provides utilities for testing Helmfile commands in a controlled environment. This package simplifies the creation and configuration of command objects for testing purposes, allowing developers to verify command behavior without executing the full application.
Components
CommandTestHelper
The core structure that encapsulates the components needed for testing commands:
Cmd: The Cobra command instanceRegistry: Flag registry for managing command flagsOptions: Command-specific options
Available Test Commands
The package provides helper functions to create test instances of the following Helmfile commands:
- TestDiffCmd(): Creates a test instance of the
diffcommand - TestApplyCmd(): Creates a test instance of the
applycommand - TestTemplateCmd(): Creates a test instance of the
templatecommand - TestSyncCmd(): Creates a test instance of the
synccommand
Usage
import (
"testing"
"github.com/helmfile/helmfile/pkg/testcommand"
)
func TestMyDiffCommand(t *testing.T) {
// Create a test diff command
helper := testcommand.TestDiffCmd()
// Access the command components
cmd := helper.Cmd
options := helper.Options.(*config.DiffOptions)
// Set up test flags
cmd.Flags().Set("concurrency", "5")
// Test command behavior
// ...
}
Implementation Details
Each test command function:
- Creates an options factory for the specific command
- Instantiates the command options
- Gets the flag registry
- Creates a Cobra command instance
- Registers the appropriate flags
- Returns a helper with all components
For the diff command, flag values are automatically transferred to the options object.
Notes
This package is intended for testing purposes only and should not be used in production code.