mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
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:
parent
aa95c51e7f
commit
3342cdf59a
27
README.md
27
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.**
|
||||
|
||||

|
||||
## 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
|
||||
|
16
plugin.go
16
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{}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user