mirror of
https://github.com/appleboy/drone-jenkins.git
synced 2026-06-04 18:23:57 +08:00
1bb020b22d
- Add `crypto/tls` import in `jenkins.go` - Add `Client` field to `Jenkins` struct - Modify `NewJenkins` function to accept an `insecure` parameter and configure HTTP client accordingly - Update `sendRequest` method to use the `Client` field from the `Jenkins` struct - Update tests in `jenkins_test.go` to include the `insecure` parameter in `NewJenkins` calls - Add `insecure` flag to CLI options in `main.go` - Add `Insecure` field to `Plugin` struct - Update `Plugin.Exec` method to pass `Insecure` field to `NewJenkins` Signed-off-by: appleboy <appleboy.tw@gmail.com>
44 lines
990 B
Go
44 lines
990 B
Go
package main
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestParseJobPath(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "appleboy",
|
|
Token: "1234",
|
|
}
|
|
jenkins := NewJenkins(auth, "http://example.com", false)
|
|
|
|
assert.Equal(t, "/job/foo", jenkins.parseJobPath("/foo/"))
|
|
assert.Equal(t, "/job/foo", jenkins.parseJobPath("foo/"))
|
|
assert.Equal(t, "/job/foo/job/bar", jenkins.parseJobPath("foo/bar"))
|
|
assert.Equal(t, "/job/foo/job/bar", jenkins.parseJobPath("foo///bar"))
|
|
}
|
|
|
|
func TestUnSupportProtocol(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "foo",
|
|
Token: "bar",
|
|
}
|
|
jenkins := NewJenkins(auth, "example.com", false)
|
|
|
|
err := jenkins.trigger("drone-jenkins", nil)
|
|
assert.NotNil(t, err)
|
|
}
|
|
|
|
func TestTriggerBuild(t *testing.T) {
|
|
auth := &Auth{
|
|
Username: "foo",
|
|
Token: "bar",
|
|
}
|
|
jenkins := NewJenkins(auth, "http://example.com", false)
|
|
|
|
err := jenkins.trigger("drone-jenkins", url.Values{"token": []string{"bar"}})
|
|
assert.Nil(t, err)
|
|
}
|