From 6e431b0c538ca45d57820983763f0b265fa8810c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 26 Sep 2018 15:35:57 +0800 Subject: [PATCH] test: add TestCommandScriptStop (#124) --- plugin_test.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/plugin_test.go b/plugin_test.go index 563c06b..3bb1cbf 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -1,13 +1,13 @@ package main import ( + "bytes" "os" + "strings" "testing" - "bytes" "github.com/appleboy/easyssh-proxy" "github.com/stretchr/testify/assert" - "strings" ) func TestMissingHostOrUser(t *testing.T) { @@ -383,6 +383,74 @@ func TestCommandOutput(t *testing.T) { assert.Equal(t, unindent(expected), unindent(buffer.String())) } +func TestScriptStop(t *testing.T) { + var ( + buffer bytes.Buffer + expected = ` + ======CMD====== + mkdir a/b/c + mkdir d/e/f + ======END====== + err: mkdir: can't create directory 'a/b/c': No such file or directory + ` + ) + + plugin := Plugin{ + Config: Config{ + Host: []string{"localhost"}, + UserName: "drone-scp", + Port: 22, + KeyPath: "./tests/.ssh/id_rsa", + Script: []string{ + "mkdir a/b/c", + "mkdir d/e/f", + }, + CommandTimeout: 10, + ScriptStop: true, + }, + Writer: &buffer, + } + + err := plugin.Exec() + assert.NotNil(t, err) + + assert.Equal(t, unindent(expected), unindent(buffer.String())) +} + +func TestNoneScriptStop(t *testing.T) { + var ( + buffer bytes.Buffer + expected = ` + ======CMD====== + mkdir a/b/c + mkdir d/e/f + ======END====== + err: mkdir: can't create directory 'a/b/c': No such file or directory + err: mkdir: can't create directory 'd/e/f': No such file or directory + ` + ) + + plugin := Plugin{ + Config: Config{ + Host: []string{"localhost"}, + UserName: "drone-scp", + Port: 22, + KeyPath: "./tests/.ssh/id_rsa", + Script: []string{ + "mkdir a/b/c", + "mkdir d/e/f", + }, + CommandTimeout: 10, + }, + Writer: &buffer, + } + + err := plugin.Exec() + assert.NotNil(t, err) + + assert.Equal(t, unindent(expected), unindent(buffer.String())) +} + func TestEnvOutput(t *testing.T) { var ( buffer bytes.Buffer