Skip to content

Commit

Permalink
test: increase test coverage for SudoCommand function
Browse files Browse the repository at this point in the history
- Add a test for the SudoCommand function

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Jan 7, 2024
1 parent ae023d7 commit d217773
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,32 @@ out: [foobar]

assert.Equal(t, unindent(expected), unindent(buffer.String()))
}

func TestSudoCommand(t *testing.T) {
var (
buffer bytes.Buffer
expected = `
======CMD======
whoami
======END======
out: drone-scp
`
)

plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Port: 22,
KeyPath: "./tests/.ssh/id_rsa",
Script: []string{
`sudo su - -c "whoami"`,
},
CommandTimeout: 10 * time.Second,
},
Writer: &buffer,
}

assert.Nil(t, plugin.Exec())
assert.Equal(t, unindent(expected), unindent(buffer.String()))
}

0 comments on commit d217773

Please sign in to comment.