Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/stackpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func StackPackCommand(cli *di.Deps) *cobra.Command {
if os.Getenv(experimentalStackpackEnvVar) != "" {
cmd.AddCommand(stackpack.StackpackScaffoldCommand(cli))
cmd.AddCommand(stackpack.StackpackPackageCommand(cli))
cmd.AddCommand(stackpack.StackpackTestCommand(cli))
cmd.AddCommand(stackpack.StackpackTestDeployCommand(cli))
}

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ const (
stackpackConfigFile = "stackpack.yaml"
)

// TestArgs contains arguments for stackpack test command
type TestArgs struct {
// TestDeployArgs contains arguments for stackpack test-deploy command
type TestDeployArgs struct {
StackpackDir string
Params map[string]string
Yes bool
UnlockedStrategy string
}

// StackpackTestCommand creates the test subcommand
func StackpackTestCommand(cli *di.Deps) *cobra.Command {
args := &TestArgs{
// StackpackTestDeployCommand creates the test-deploy subcommand
func StackpackTestDeployCommand(cli *di.Deps) *cobra.Command {
args := &TestDeployArgs{
Params: make(map[string]string),
}
cmd := &cobra.Command{
Use: "test",
Use: "test-deploy",
Short: "Test a stackpack by packaging, uploading, and installing/upgrading",
Long: `Test a stackpack by running package, upload, and install/upgrade commands in sequence.

Expand All @@ -50,17 +50,17 @@ This command will:
The original stackpack directory is left untouched. The version is automatically incremented for each test run.
The stackpack name is read from ` + stackpackConfigFile + `, so no --name flag is required.`,
Example: `# Test stackpack with confirmation
sts stackpack test -p "param1=value1"
sts stackpack test-deploy -p "param1=value1"

# Skip confirmation prompt
sts stackpack test --yes
sts stackpack test-deploy --yes

# Test stackpack in specific directory with unlocked strategy
sts stackpack test -d ./my-stackpack --yes --unlocked-strategy force
sts stackpack test-deploy -d ./my-stackpack --yes --unlocked-strategy force

# Test with custom unlocked strategy
sts stackpack test --unlocked-strategy skip --yes`,
RunE: cli.CmdRunEWithApi(RunStackpackTestCommand(args)),
sts stackpack test-deploy --unlocked-strategy skip --yes`,
RunE: cli.CmdRunEWithApi(RunStackpackTestDeployCommand(args)),
}

cmd.Flags().StringVarP(&args.StackpackDir, "stackpack-directory", "d", "", "Path to stackpack directory (defaults to current directory)")
Expand All @@ -71,19 +71,19 @@ sts stackpack test --unlocked-strategy skip --yes`,
return cmd
}

// RunStackpackTestCommand executes the test command
// RunStackpackTestDeployCommand executes the test-deploy command
//
//nolint:funlen
func RunStackpackTestCommand(args *TestArgs) di.CmdWithApiFn {
func RunStackpackTestDeployCommand(args *TestDeployArgs) di.CmdWithApiFn {
return func(
cmd *cobra.Command,
cli *di.Deps,
api *stackstate_api.APIClient,
serverInfo *stackstate_api.ServerInfo,
) common.CLIError {
// Warn if JSON output is requested - not meaningful for test command
// Warn if JSON output is requested - not meaningful for test-deploy command
if cli.IsJson() {
cli.Printer.PrintLn("Warning: JSON output format is not meaningful for the test command, proceeding with text output")
cli.Printer.PrintLn("Warning: JSON output format is not meaningful for the test-deploy command, proceeding with text output")
}

// Set default stackpack directory
Expand All @@ -103,7 +103,7 @@ func RunStackpackTestCommand(args *TestArgs) di.CmdWithApiFn {
return common.NewRuntimeError(fmt.Errorf("failed to parse %s: %w", stackpackConfigFile, err))
}

cli.Printer.Success("Starting stackpack test sequence...")
cli.Printer.Success("Starting stackpack test-deploy sequence...")
cli.Printer.PrintLn(fmt.Sprintf(" Stackpack: %s (current version: %s)", originalInfo.Name, originalInfo.Version))
cli.Printer.PrintLn("")

Expand Down Expand Up @@ -239,7 +239,7 @@ func RunStackpackTestCommand(args *TestArgs) di.CmdWithApiFn {
}

cli.Printer.PrintLn("")
cli.Printer.Success("🎉 Test sequence completed successfully!")
cli.Printer.Success("🎉 Test-deploy sequence completed successfully!")

// Clean up .sts file
if err := os.Remove(packageArgs.ArchiveFile); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
"github.com/stretchr/testify/require"
)

// setupStackpackTestCmd creates a test command with mock dependencies
func setupStackpackTestCmd(t *testing.T) (*di.MockDeps, *cobra.Command) {
// setupStackpackTestDeployCmd creates a test command with mock dependencies
func setupStackpackTestDeployCmd(t *testing.T) (*di.MockDeps, *cobra.Command) {
cli := di.NewMockDeps(t)
cmd := StackpackTestCommand(&cli.Deps)
cmd := StackpackTestDeployCommand(&cli.Deps)
return &cli, cmd
}

func TestStackpackTestCommand_FlagsAndStructure(t *testing.T) {
_, cmd := setupStackpackTestCmd(t)
func TestStackpackTestDeployCommand_FlagsAndStructure(t *testing.T) {
_, cmd := setupStackpackTestDeployCmd(t)

// Test command structure
assert.Equal(t, "test", cmd.Use)
assert.Equal(t, "test-deploy", cmd.Use)
assert.Contains(t, cmd.Short, "Test a stackpack")
assert.Contains(t, cmd.Long, "package, upload, and install")
assert.NotEmpty(t, cmd.Example)
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestCopyDirectory(t *testing.T) {
assert.Equal(t, testContent, string(copiedContent2))
}

func TestStackpackTestCommand_RequiredFlags(t *testing.T) {
func TestStackpackTestDeployCommand_RequiredFlags(t *testing.T) {
tests := []struct {
name string
args []string
Expand All @@ -184,7 +184,7 @@ func TestStackpackTestCommand_RequiredFlags(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli, cmd := setupStackpackTestCmd(t)
cli, cmd := setupStackpackTestDeployCmd(t)
_, err := di.ExecuteCommandWithContext(&cli.Deps, cmd, tt.args...)

if tt.wantErr {
Expand All @@ -202,7 +202,7 @@ func TestStackpackTestCommand_RequiredFlags(t *testing.T) {
}
}

func TestStackpackTestCommand_DirectoryHandling(t *testing.T) {
func TestStackpackTestDeployCommand_DirectoryHandling(t *testing.T) {
// Create temporary directory with valid stackpack structure
tempDir, err := os.MkdirTemp("", "stackpack-test-dir-*")
require.NoError(t, err)
Expand All @@ -214,7 +214,7 @@ func TestStackpackTestCommand_DirectoryHandling(t *testing.T) {
// Create required files
createTestStackpack(t, stackpackDir, "test-stackpack", "1.0.0")

cli, cmd := setupStackpackTestCmd(t)
cli, cmd := setupStackpackTestDeployCmd(t)

tests := []struct {
name string
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestCompareVersionsSemver(t *testing.T) {
}
}

func TestStackpackTestCommand_InstallUpgradeLogic(t *testing.T) {
func TestStackpackTestDeployCommand_InstallUpgradeLogic(t *testing.T) {
tests := []struct {
name string
installedVersion string
Expand Down
2 changes: 1 addition & 1 deletion cmd/stackpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestStackPackCommand_FeatureGating(t *testing.T) {
},
}

experimentalCommands := []string{"scaffold", "package", "test"}
experimentalCommands := []string{"scaffold", "package", "test-deploy"}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down