1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-11 13:53:53 +02:00
sap-jenkins-library/pkg/mock/httpClient_test.go
Vitalii Sidorov 2a4052d13c
feat(helmExecute): run complete lint, build, publish cycle (#3546)
* Add runHelmCommand

* Add dryRun for debug

* Add default case in helmExecute

* Fix unit-tests

* small fix

* Fix RunHelmAdd and change RunHelmPublish methods

* Fix RunHelmPublish

* Fix unit-tests

* Fix unit-test

* small fix

* small fix

* small fix

* Add LintFlag PackageFlag PublishFlag flags

* Add tests for httpClient.go

* test

* test

* smal fix

* small fix

* Add getting name and version from Chart.yaml

* Add test

* Fix

* small fix

* Fix according to comments

* small fix

Co-authored-by: “Vitalii <“vitalii.sidorov@sap.com”>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
Co-authored-by: Vitalii Sidorov <vitalii_sidorov@sap.com>
2022-03-17 17:13:34 +01:00

113 lines
2.3 KiB
Go

//go:build !release
// +build !release
package mock
import (
"io"
"net/http"
"testing"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/stretchr/testify/assert"
)
func TestSendRequest(t *testing.T) {
t.Parallel()
t.Run("SendRequest", func(t *testing.T) {
utils := HttpClientMock{}
method := "PUT"
url := "https://localhost"
var header http.Header
var r io.Reader
var cookies []*http.Cookie
_, err := utils.SendRequest(method, url, r, header, cookies)
assert.Error(t, err)
})
}
func TestSetOption(t *testing.T) {
t.Parallel()
t.Run("SetOption", func(t *testing.T) {
utils := HttpClientMock{}
options := []piperhttp.ClientOptions{
{
Username: "user",
Password: "pwd",
},
{
Username: "user2",
Password: "pwd2",
},
}
for _, option := range options {
utils.SetOptions(option)
}
assert.Equal(t, options, utils.ClientOptions)
})
}
func TestUpload(t *testing.T) {
t.Parallel()
t.Run("Upload", func(t *testing.T) {
utils := HttpClientMock{}
data := piperhttp.UploadRequestData{}
_, err := utils.Upload(data)
assert.Error(t, err)
})
}
func TestUploadRequest(t *testing.T) {
t.Parallel()
t.Run("UploadRequest", func(t *testing.T) {
utils := HttpClientMock{
ReturnFileUploadStatus: 200,
FileUploads: map[string]string{
"key": "value",
},
}
method := "PUT"
url := "https://localhost"
file := "test-7.8.9.tgz"
fieldName := ""
uploadType := ""
var header http.Header
var cookies []*http.Cookie
returnFileUploadStatus := 200
response, err := utils.UploadRequest(method, url, file, fieldName, header, cookies, uploadType)
assert.NoError(t, err)
assert.Equal(t, returnFileUploadStatus, response.StatusCode)
})
}
func TestUploadFile(t *testing.T) {
t.Parallel()
t.Run("UploadFile", func(t *testing.T) {
utils := HttpClientMock{
ReturnFileUploadStatus: 200,
FileUploads: map[string]string{
"key": "value",
},
}
url := "https://localhost"
file := "test-7.8.9.tgz"
fieldName := ""
uploadType := ""
var header http.Header
var cookies []*http.Cookie
returnFileUploadStatus := 200
response, err := utils.UploadFile(url, file, fieldName, header, cookies, uploadType)
assert.NoError(t, err)
assert.Equal(t, returnFileUploadStatus, response.StatusCode)
})
}