From 3342cdf59aa8c09e72c544d5eaac315a1612e126 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 4 Mar 2019 14:47:28 +0800 Subject: [PATCH] refactor: error var missingXXX should have name of the form errFoo Signed-off-by: Bo-Yi Wu --- README.md | 27 +++++++++++++++++++++++---- plugin.go | 16 ++++++++-------- plugin_test.go | 6 +++--- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4f46da2..5e60b8c 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,32 @@ information and a listing of the available options please take a look at [the do **Note: Please update your image config path to `appleboy/drone-ssh` for drone. `plugins/ssh` is no longer maintained.** ![demo](./images/demo2017.05.10.gif) -## Build -Build the binary with the following commands: +## Build or Download a binary + +The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-ssh/releases). Support the following OS type. + +* Windows amd64/386 +* Linux arm/amd64/386 +* Darwin amd64/386 + +With `Go` installed ``` -go build -go test +$ go get -u -v github.com/appleboy/drone-ssh +``` + +or build the binary with the following command: + +``` +$ export GOOS=linux +$ export GOARCH=amd64 +$ export CGO_ENABLED=0 +$ export GO111MODULE=on + +$ go test -cover ./... + +$ go build -v -a -tags netgo -o release/linux/amd64/drone-ssh . ``` ## Docker diff --git a/plugin.go b/plugin.go index 9f0ef26..36a524c 100644 --- a/plugin.go +++ b/plugin.go @@ -14,10 +14,10 @@ import ( ) var ( - missingHost = errors.New("Error: missing server host") - missingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") - commandTimeOut = errors.New("Error: command timeout") - setPasswordandKey = errors.New("can't set password and key at the same time") + errMissingHost = errors.New("Error: missing server host") + errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") + errCommandTimeOut = errors.New("Error: command timeout") + errSetPasswordandKey = errors.New("can't set password and key at the same time") ) type ( @@ -118,7 +118,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) { // command time out if !isTimeout { - errChannel <- commandTimeOut + errChannel <- errCommandTimeOut } } @@ -139,15 +139,15 @@ func (p Plugin) log(host string, message ...interface{}) { // Exec executes the plugin. func (p Plugin) Exec() error { if len(p.Config.Host) == 0 { - return missingHost + return errMissingHost } if len(p.Config.Key) == 0 && len(p.Config.Password) == 0 && len(p.Config.KeyPath) == 0 { - return missingPasswordOrKey + return errMissingPasswordOrKey } if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 { - return setPasswordandKey + return errSetPasswordandKey } wg := sync.WaitGroup{} diff --git a/plugin_test.go b/plugin_test.go index fcb0738..1067328 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -16,7 +16,7 @@ func TestMissingHostOrUser(t *testing.T) { err := plugin.Exec() assert.NotNil(t, err) - assert.Equal(t, missingHost, err) + assert.Equal(t, errMissingHost, err) } func TestMissingKeyOrPassword(t *testing.T) { @@ -31,7 +31,7 @@ func TestMissingKeyOrPassword(t *testing.T) { err := plugin.Exec() assert.NotNil(t, err) - assert.Equal(t, missingPasswordOrKey, err) + assert.Equal(t, errMissingPasswordOrKey, err) } func TestSetPasswordAndKey(t *testing.T) { @@ -48,7 +48,7 @@ func TestSetPasswordAndKey(t *testing.T) { err := plugin.Exec() assert.NotNil(t, err) - assert.Equal(t, setPasswordandKey, err) + assert.Equal(t, errSetPasswordandKey, err) } func TestIncorrectPassword(t *testing.T) {