File tree Expand file tree Collapse file tree 1 file changed +70
-2
lines changed Expand file tree Collapse file tree 1 file changed +70
-2
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
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
1313func 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+
386454func TestEnvOutput (t * testing.T ) {
387455 var (
388456 buffer bytes.Buffer
You can’t perform that action at this time.
0 commit comments