Skip to content

Commit 8a825a1

Browse files
committed
test: cover remaining log grouping patch paths
1 parent 0fb67b2 commit 8a825a1

2 files changed

Lines changed: 111 additions & 0 deletions

File tree

cmd/cmd_utils_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818

1919
errUtils "github.com/cloudposse/atmos/errors"
2020
e "github.com/cloudposse/atmos/internal/exec"
21+
"github.com/cloudposse/atmos/pkg/ci"
22+
githubprovider "github.com/cloudposse/atmos/pkg/ci/providers/github"
2123
envpkg "github.com/cloudposse/atmos/pkg/env"
2224
"github.com/cloudposse/atmos/pkg/perf"
2325
"github.com/cloudposse/atmos/pkg/reexec"
@@ -2136,6 +2138,44 @@ func TestProcessCustomCommands(t *testing.T) {
21362138
}
21372139
}
21382140

2141+
func TestExecuteCustomCommandShellStepPropagatesCILogGroupSentinel(t *testing.T) {
2142+
_ = NewTestKit(t)
2143+
2144+
restore := ci.SwapRegistryForTest()
2145+
t.Cleanup(restore)
2146+
ci.Register(githubprovider.NewProvider())
2147+
t.Setenv("GITHUB_ACTIONS", "true")
2148+
2149+
workDir := t.TempDir()
2150+
sentinelFile := filepath.Join(workDir, "sentinel.txt")
2151+
atmosConfig := schema.AtmosConfiguration{
2152+
BasePath: workDir,
2153+
CI: schema.CIConfig{Enabled: true},
2154+
}
2155+
parentCmd := &cobra.Command{Use: "atmos"}
2156+
commands := []schema.Command{{
2157+
Name: "cover-ci-shell",
2158+
Description: "exercise shell dispatch with CI grouping",
2159+
WorkingDirectory: workDir,
2160+
Steps: []schema.Task{{
2161+
Name: "capture-sentinel",
2162+
Type: schema.TaskTypeShell,
2163+
Command: `printf %s "$ATMOS_CI_LOG_GROUP_ACTIVE" > sentinel.txt`,
2164+
}},
2165+
}}
2166+
2167+
require.NoError(t, processCustomCommands(atmosConfig, commands, parentCmd))
2168+
customCmd := findSubcommand(parentCmd, "cover-ci-shell")
2169+
require.NotNil(t, customCmd)
2170+
2171+
customCmd.PreRun(customCmd, nil)
2172+
customCmd.Run(customCmd, nil)
2173+
2174+
got, err := os.ReadFile(sentinelFile)
2175+
require.NoError(t, err)
2176+
assert.Equal(t, "1", string(got))
2177+
}
2178+
21392179
func TestFindTypedValue(t *testing.T) {
21402180
tests := []struct {
21412181
name string

internal/exec/workflow_utils_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,77 @@ func TestExecuteWorkflow_DryRunBackgroundAndControlSteps(t *testing.T) {
14561456
require.NoError(t, err)
14571457
}
14581458

1459+
func TestExecuteWorkflow_DryRunShellStepContainerOverride(t *testing.T) {
1460+
stacksPath := "../../tests/fixtures/scenarios/workflows"
1461+
t.Setenv("ATMOS_CLI_CONFIG_PATH", stacksPath)
1462+
t.Setenv("ATMOS_BASE_PATH", stacksPath)
1463+
1464+
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
1465+
require.NoError(t, err)
1466+
1467+
workflowDef := &schema.WorkflowDefinition{
1468+
Description: "Test shell step container override in dry run",
1469+
Steps: []schema.WorkflowStep{{
1470+
Name: "step-container",
1471+
Type: schema.TaskTypeShell,
1472+
Command: "echo in step container",
1473+
Container: &schema.WorkflowContainer{
1474+
Image: "alpine:latest",
1475+
},
1476+
}},
1477+
}
1478+
1479+
err = ExecuteWorkflow(atmosConfig, "test-step-container", "/path/to/workflow.yaml", workflowDef, true, "", "", "")
1480+
require.NoError(t, err)
1481+
}
1482+
1483+
func TestExecuteWorkflow_DryRunShellWorkflowContainer(t *testing.T) {
1484+
stacksPath := "../../tests/fixtures/scenarios/workflows"
1485+
t.Setenv("ATMOS_CLI_CONFIG_PATH", stacksPath)
1486+
t.Setenv("ATMOS_BASE_PATH", stacksPath)
1487+
1488+
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
1489+
require.NoError(t, err)
1490+
1491+
workflowDef := &schema.WorkflowDefinition{
1492+
Description: "Test workflow container shell step in dry run",
1493+
Container: &schema.WorkflowContainer{
1494+
Image: "alpine:latest",
1495+
},
1496+
Output: "none",
1497+
Steps: []schema.WorkflowStep{{
1498+
Name: "workflow-container",
1499+
Type: schema.TaskTypeShell,
1500+
Command: "echo in workflow container",
1501+
}},
1502+
}
1503+
1504+
err = ExecuteWorkflow(atmosConfig, "test-workflow-container", "/path/to/workflow.yaml", workflowDef, true, "", "", "")
1505+
require.NoError(t, err)
1506+
}
1507+
1508+
func TestExecuteWorkflow_DryRunAtmosStepStackBeforeSeparator(t *testing.T) {
1509+
stacksPath := "../../tests/fixtures/scenarios/workflows"
1510+
t.Setenv("ATMOS_CLI_CONFIG_PATH", stacksPath)
1511+
t.Setenv("ATMOS_BASE_PATH", stacksPath)
1512+
1513+
atmosConfig, err := cfg.InitCliConfig(schema.ConfigAndStacksInfo{}, false)
1514+
require.NoError(t, err)
1515+
1516+
workflowDef := &schema.WorkflowDefinition{
1517+
Description: "Test atmos step stack insertion before separator",
1518+
Steps: []schema.WorkflowStep{{
1519+
Name: "plan",
1520+
Type: schema.TaskTypeAtmos,
1521+
Command: "terraform plan vpc -- -target=module.example",
1522+
Stack: "tenant1-ue2-dev",
1523+
}},
1524+
}
1525+
1526+
err = ExecuteWorkflow(atmosConfig, "test-atmos-stack-before-separator", "/path/to/workflow.yaml", workflowDef, true, "", "", "")
1527+
require.NoError(t, err)
1528+
}
1529+
14591530
func registerGitHubLogGroupingForWorkflowTest(t *testing.T) {
14601531
t.Helper()
14611532

0 commit comments

Comments
 (0)