1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/gctsDeploy_test.go
Chris Bo 25decaa256
Introducing new step 'gctsRollback' (#1526)
* added new step gctsDeployCommit

* suggested PR fixes applied

* fixed test

* Remove unused imports

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* added URL encoding for 'request' parameter

* regenerate after change

* add new step gctsRollbackCommit

* fixed typo in docu

* enhanced error messages

* minor changes

* renamed step to 'gctsDeploy'

* changed name

* remove space

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>

* changed step name to gctsRollback

* changed function name

* fix conflict

* fixed gctsDeploy step name

* fix typo

* fixed error handling

* added Jenkins credentials for github token

* regenerated

* newly generated

* removed calling piper binary with go function call

* removed unused execRunner parameter

* cleaned up

* fixed merge conflict

* added docu page

* cleaned up

* provide Jenkins creds also in config.yaml

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-07-23 20:20:07 +02:00

112 lines
2.5 KiB
Go

package cmd
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGctsDeploySuccess(t *testing.T) {
config := gctsDeployOptions{
Host: "http://testHost.com:50000",
Client: "000",
Repository: "testRepo",
Username: "testUser",
Password: "testPassword",
}
t.Run("deploy latest commit", func(t *testing.T) {
httpClient := httpMockGcts{StatusCode: 200, ResponseBody: `{
"trkorr": "SIDK1234567",
"fromCommit": "f1cdb6a032c1d8187c0990b51e94e8d8bb9898b2",
"toCommit": "f1cdb6a032c1d8187c0990b51e94e8d8bb9898b2",
"log": [
{
"time": 20180606130524,
"user": "JENKINS",
"section": "REPOSITORY_FACTORY",
"action": "CREATE_REPOSITORY",
"severity": "INFO",
"message": "Start action CREATE_REPOSITORY review",
"code": "GCTS.API.410"
}
]
}`}
err := deployCommit(&config, nil, &httpClient)
if assert.NoError(t, err) {
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "http://testHost.com:50000/sap/bc/cts_abapvcs/repository/testRepo/pullByCommit?sap-client=000", httpClient.URL)
})
t.Run("check method", func(t *testing.T) {
assert.Equal(t, "GET", httpClient.Method)
})
t.Run("check user", func(t *testing.T) {
assert.Equal(t, "testUser", httpClient.Options.Username)
})
t.Run("check password", func(t *testing.T) {
assert.Equal(t, "testPassword", httpClient.Options.Password)
})
}
})
}
func TestGctsDeployFailure(t *testing.T) {
config := gctsDeployOptions{
Host: "http://testHost.com:50000",
Client: "000",
Repository: "testRepo",
Username: "testUser",
Password: "testPassword",
}
t.Run("http error occurred", func(t *testing.T) {
httpClient := httpMockGcts{StatusCode: 500, ResponseBody: `{
"log": [
{
"time": 20180606130524,
"user": "JENKINS",
"section": "REPOSITORY_FACTORY",
"action": "CREATE_REPOSITORY",
"severity": "INFO",
"message": "Start action CREATE_REPOSITORY review",
"code": "GCTS.API.410"
}
],
"errorLog": [
{
"time": 20180606130524,
"user": "JENKINS",
"section": "REPOSITORY_FACTORY",
"action": "CREATE_REPOSITORY",
"severity": "INFO",
"message": "Start action CREATE_REPOSITORY review",
"code": "GCTS.API.410"
}
],
"exception": {
"message": "repository_not_found",
"description": "Repository not found",
"code": 404
}
}`}
err := deployCommit(&config, nil, &httpClient)
assert.EqualError(t, err, "a http error occurred")
})
}