Skip to content

Commit

Permalink
add condition test with sudo
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 20, 2024
1 parent c0c8057 commit 62a6778
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/runner/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,22 @@ func Test_execCmd(t *testing.T) {
assert.Equal(t, " {script: /bin/sh -c 'echo condition true'}", resp.details)
})

t.Run("condition true, sudo only", func(t *testing.T) {
// check without sudo condition on root-only file
ec := execCmd{exec: sess, tsk: &config.Task{Name: "test"}, cmd: config.Cmd{Condition: "cat /etc/shadow",
Script: "echo condition true", Name: "test"}}
resp, err := ec.Script(ctx)
require.NoError(t, err)
assert.Equal(t, " {skip: test}", resp.details)

// check with sudo condition on root-only file
ec = execCmd{exec: sess, tsk: &config.Task{Name: "test"}, cmd: config.Cmd{Condition: "cat /etc/shadow",
Script: "echo condition true", Name: "test", Options: config.CmdOptions{Sudo: true}}}
resp, err = ec.Script(ctx)
require.NoError(t, err)
assert.Equal(t, " {script: /bin/sh -c 'echo condition true', sudo: true}", resp.details)
})

t.Run("condition true inverted", func(t *testing.T) {
_, err := sess.Run(ctx, "sudo touch /srv/test.condition", &executor.RunOpts{Verbose: true})
require.NoError(t, err)
Expand Down

0 comments on commit 62a6778

Please sign in to comment.