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 1
1
package main
2
2
3
3
import (
4
+ "bytes"
4
5
"os"
6
+ "strings"
5
7
"testing"
6
8
7
- "bytes"
8
9
"github.com/appleboy/easyssh-proxy"
9
10
"github.com/stretchr/testify/assert"
10
- "strings"
11
11
)
12
12
13
13
func TestMissingHostOrUser (t * testing.T ) {
@@ -383,6 +383,74 @@ func TestCommandOutput(t *testing.T) {
383
383
assert .Equal (t , unindent (expected ), unindent (buffer .String ()))
384
384
}
385
385
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
+
386
454
func TestEnvOutput (t * testing.T ) {
387
455
var (
388
456
buffer bytes.Buffer
You can’t perform that action at this time.
0 commit comments