Skip to content

Commit

Permalink
bash flag tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Dec 4, 2024
1 parent c5a0952 commit 5b1a2ac
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions tooling/templatize/pkg/pipeline/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,52 @@ func TestMapStepVariables(t *testing.T) {
}

func TestRunShellStep(t *testing.T) {
expectedOutput := "hello\n"
s := &Step{
Command: "echo hello",
outputFunc: func(output string) {
assert.Equal(t, output, expectedOutput)
testCases := []struct {
name string
vars config.Variables
step *Step
err string
}{
{
name: "basic",
vars: config.Variables{},
step: &Step{
Command: "echo hello",
},
},
{
name: "test nounset",
vars: config.Variables{},
step: &Step{
Command: "echo $DOES_NOT_EXIST",
},
err: "failed to execute shell command: /bin/bash: line 3: DOES_NOT_EXIST: unbound variable\n exit status 1",
},
{
name: "test errexit",
vars: config.Variables{},
step: &Step{
Command: "ls /does-not-exist ; echo hello",
},
err: "failed to execute shell command: ls: /does-not-exist: No such file or directory\n exit status 1",
},
{
name: "test pipefail",
vars: config.Variables{},
step: &Step{
Command: "ls /does-not-exist | echo",
},
err: "failed to execute shell command: \nls: /does-not-exist: No such file or directory\n exit status 1",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := tc.step.runShellStep(context.Background(), "", &PipelineRunOptions{})
if tc.err != "" {
assert.Error(t, err, tc.err)
} else {
assert.NilError(t, err)
}
})
}
err := s.runShellStep(context.Background(), "", &PipelineRunOptions{})
assert.NilError(t, err)
}

0 comments on commit 5b1a2ac

Please sign in to comment.