refactor: error var missingXXX should have name of the form errFoo

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2019-03-04 14:47:28 +08:00
parent aa95c51e7f
commit 3342cdf59a
3 changed files with 34 additions and 15 deletions

View File

@ -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.** **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) ![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 get -u -v github.com/appleboy/drone-ssh
go test ```
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 ## Docker

View File

@ -14,10 +14,10 @@ import (
) )
var ( var (
missingHost = errors.New("Error: missing server host") errMissingHost = errors.New("Error: missing server host")
missingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password") errMissingPasswordOrKey = errors.New("Error: can't connect without a private SSH key or password")
commandTimeOut = errors.New("Error: command timeout") errCommandTimeOut = errors.New("Error: command timeout")
setPasswordandKey = errors.New("can't set password and key at the same time") errSetPasswordandKey = errors.New("can't set password and key at the same time")
) )
type ( type (
@ -118,7 +118,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
// command time out // command time out
if !isTimeout { if !isTimeout {
errChannel <- commandTimeOut errChannel <- errCommandTimeOut
} }
} }
@ -139,15 +139,15 @@ func (p Plugin) log(host string, message ...interface{}) {
// Exec executes the plugin. // Exec executes the plugin.
func (p Plugin) Exec() error { func (p Plugin) Exec() error {
if len(p.Config.Host) == 0 { 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 { 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 { if len(p.Config.Key) != 0 && len(p.Config.Password) != 0 {
return setPasswordandKey return errSetPasswordandKey
} }
wg := sync.WaitGroup{} wg := sync.WaitGroup{}

View File

@ -16,7 +16,7 @@ func TestMissingHostOrUser(t *testing.T) {
err := plugin.Exec() err := plugin.Exec()
assert.NotNil(t, err) assert.NotNil(t, err)
assert.Equal(t, missingHost, err) assert.Equal(t, errMissingHost, err)
} }
func TestMissingKeyOrPassword(t *testing.T) { func TestMissingKeyOrPassword(t *testing.T) {
@ -31,7 +31,7 @@ func TestMissingKeyOrPassword(t *testing.T) {
err := plugin.Exec() err := plugin.Exec()
assert.NotNil(t, err) assert.NotNil(t, err)
assert.Equal(t, missingPasswordOrKey, err) assert.Equal(t, errMissingPasswordOrKey, err)
} }
func TestSetPasswordAndKey(t *testing.T) { func TestSetPasswordAndKey(t *testing.T) {
@ -48,7 +48,7 @@ func TestSetPasswordAndKey(t *testing.T) {
err := plugin.Exec() err := plugin.Exec()
assert.NotNil(t, err) assert.NotNil(t, err)
assert.Equal(t, setPasswordandKey, err) assert.Equal(t, errSetPasswordandKey, err)
} }
func TestIncorrectPassword(t *testing.T) { func TestIncorrectPassword(t *testing.T) {