Add plugin testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2016-10-15 23:44:11 +08:00
parent 5257dc754c
commit 92fd06c78a
5 changed files with 73 additions and 3 deletions
+1 -1
View File
@@ -23,5 +23,5 @@ _testmain.go
*.test
*.prof
vendor
drone-telegram
drone-jenkins
coverage.txt
+1 -1
View File
@@ -1,4 +1,4 @@
.PHONY: install build test html update docker_build docker_image docker_deploy clean
.PHONY: install build test html update docker_build docker_image docker docker_deploy clean
VERSION := $(shell git describe --tags || git rev-parse --short HEAD)
DEPLOY_ACCOUNT := "appleboy"
+1
View File
@@ -42,6 +42,7 @@ Execute from the working directory:
```
docker run --rm \
-e PLUGIN_BASE_URL=http://example.com \
-e PLUGIN_USERNAME=xxxxxxx \
-e PLUGIN_TOKEN=xxxxxxx \
-e PLUGIN_JOB=xxxxxxx \
-1
View File
@@ -34,7 +34,6 @@ func NewJenkins(auth *Auth, url string) *Jenkins {
func (jenkins *Jenkins) buildURL(path string, params url.Values) (requestURL string) {
requestURL = jenkins.BaseURL + path
fmt.Println(requestURL)
if params != nil {
queryString := params.Encode()
if queryString != "" {
+70
View File
@@ -0,0 +1,70 @@
package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestMissingConfig(t *testing.T) {
var plugin Plugin
err := plugin.Exec()
assert.NotNil(t, err)
}
func TestMissingJenkinsConfig(t *testing.T) {
plugin := Plugin{
Config: Config{
BaseURL: "http://example.com",
},
}
err := plugin.Exec()
assert.NotNil(t, err)
}
func TestPluginTriggerBuild(t *testing.T) {
plugin := Plugin{
Repo: Repo{
Name: "go-hello",
Owner: "appleboy",
},
Build: Build{
Number: 101,
Status: "success",
Link: "https://github.com/appleboy/go-hello",
Author: "Bo-Yi Wu",
Branch: "master",
Message: "update by drone line plugin.",
Commit: "e7c4f0a63ceeb42a39ac7806f7b51f3f0d204fd2",
},
Config: Config{
BaseURL: "http://example.com",
Username: "foo",
Token: "bar",
Job: []string{"drone-jenkins"},
},
}
err := plugin.Exec()
assert.Nil(t, err)
}
func TestTrimElement(t *testing.T) {
var input, result []string
input = []string{"1", " ", "3"}
result = []string{"1", "3"}
assert.Equal(t, result, trimElement(input))
input = []string{"1", "2"}
result = []string{"1", "2"}
assert.Equal(t, result, trimElement(input))
}