Skip to content

Commit 6e431b0

Browse files
authored
test: add TestCommandScriptStop (#124)
1 parent 3499506 commit 6e431b0

File tree

1 file changed

+70
-2
lines changed

1 file changed

+70
-2
lines changed

plugin_test.go

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package main
22

33
import (
4+
"bytes"
45
"os"
6+
"strings"
57
"testing"
68

7-
"bytes"
89
"github.com/appleboy/easyssh-proxy"
910
"github.com/stretchr/testify/assert"
10-
"strings"
1111
)
1212

1313
func TestMissingHostOrUser(t *testing.T) {
@@ -383,6 +383,74 @@ func TestCommandOutput(t *testing.T) {
383383
assert.Equal(t, unindent(expected), unindent(buffer.String()))
384384
}
385385

386+
func TestScriptStop(t *testing.T) {
387+
var (
388+
buffer bytes.Buffer
389+
expected = `
390+
======CMD======
391+
mkdir a/b/c
392+
mkdir d/e/f
393+
======END======
394+
err: mkdir: can't create directory 'a/b/c': No such file or directory
395+
`
396+
)
397+
398+
plugin := Plugin{
399+
Config: Config{
400+
Host: []string{"localhost"},
401+
UserName: "drone-scp",
402+
Port: 22,
403+
KeyPath: "./tests/.ssh/id_rsa",
404+
Script: []string{
405+
"mkdir a/b/c",
406+
"mkdir d/e/f",
407+
},
408+
CommandTimeout: 10,
409+
ScriptStop: true,
410+
},
411+
Writer: &buffer,
412+
}
413+
414+
err := plugin.Exec()
415+
assert.NotNil(t, err)
416+
417+
assert.Equal(t, unindent(expected), unindent(buffer.String()))
418+
}
419+
420+
func TestNoneScriptStop(t *testing.T) {
421+
var (
422+
buffer bytes.Buffer
423+
expected = `
424+
======CMD======
425+
mkdir a/b/c
426+
mkdir d/e/f
427+
======END======
428+
err: mkdir: can't create directory 'a/b/c': No such file or directory
429+
err: mkdir: can't create directory 'd/e/f': No such file or directory
430+
`
431+
)
432+
433+
plugin := Plugin{
434+
Config: Config{
435+
Host: []string{"localhost"},
436+
UserName: "drone-scp",
437+
Port: 22,
438+
KeyPath: "./tests/.ssh/id_rsa",
439+
Script: []string{
440+
"mkdir a/b/c",
441+
"mkdir d/e/f",
442+
},
443+
CommandTimeout: 10,
444+
},
445+
Writer: &buffer,
446+
}
447+
448+
err := plugin.Exec()
449+
assert.NotNil(t, err)
450+
451+
assert.Equal(t, unindent(expected), unindent(buffer.String()))
452+
}
453+
386454
func TestEnvOutput(t *testing.T) {
387455
var (
388456
buffer bytes.Buffer

0 commit comments

Comments
 (0)