mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
* Add small fix * fix unit-tests * Add deploymentName and packageVersion as flags * small fix * Change getting version of helm chart * small fix Co-authored-by: “Vitalii <“vitalii.sidorov@sap.com”> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
//go:build !release
|
|
// +build !release
|
|
|
|
package mock
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
|
)
|
|
|
|
// HttpClientMock mock struct
|
|
type HttpClientMock struct {
|
|
ClientOptions []piperhttp.ClientOptions // set by mock
|
|
FileUploads map[string]string // set by mock
|
|
ReturnFileUploadStatus int // expected to be set upfront
|
|
ReturnFileUploadError error // expected to be set upfront
|
|
}
|
|
|
|
// SendRequest mock
|
|
func (utils *HttpClientMock) SendRequest(method string, url string, r io.Reader, header http.Header, cookies []*http.Cookie) (*http.Response, error) {
|
|
return nil, fmt.Errorf("not implemented")
|
|
}
|
|
|
|
// SetOptions mock
|
|
func (utils *HttpClientMock) SetOptions(options piperhttp.ClientOptions) {
|
|
utils.ClientOptions = append(utils.ClientOptions, options)
|
|
}
|
|
|
|
// Upload mock
|
|
func (utils *HttpClientMock) Upload(data piperhttp.UploadRequestData) (*http.Response, error) {
|
|
return nil, fmt.Errorf("not implemented")
|
|
}
|
|
|
|
// UploadRequest mock
|
|
func (utils *HttpClientMock) UploadRequest(method, url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
|
|
utils.FileUploads[file] = url
|
|
|
|
response := http.Response{
|
|
StatusCode: utils.ReturnFileUploadStatus,
|
|
}
|
|
|
|
return &response, utils.ReturnFileUploadError
|
|
}
|
|
|
|
// UploadFile mock
|
|
func (utils *HttpClientMock) UploadFile(url, file, fieldName string, header http.Header, cookies []*http.Cookie, uploadType string) (*http.Response, error) {
|
|
return utils.UploadRequest(http.MethodPut, url, file, fieldName, header, cookies, uploadType)
|
|
}
|
|
|
|
// DownloadFile mock
|
|
func (utils *HttpClientMock) DownloadFile(url, filename string, header http.Header, cookies []*http.Cookie) error {
|
|
return fmt.Errorf("not implemented")
|
|
}
|