From d217773bacfbc83571afd8fa9a9a70f3b29713c0 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 7 Jan 2024 17:40:23 +0800 Subject: [PATCH] test: increase test coverage for SudoCommand function - Add a test for the SudoCommand function Signed-off-by: Bo-Yi Wu --- plugin_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugin_test.go b/plugin_test.go index ac301ac..45cf264 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -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())) +}