Files
plugin-drone-jenkins/jenkins_test.go
T
Bo-Yi Wu 1bb020b22d feat: add support for insecure TLS connections (#34)
- 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>
2024-10-05 08:41:53 +08:00

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)
}