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 abdc3f736b
Introducing new step 'gctsDeployCommit' (#1476)
* 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

* minor changes

* renamed step to 'gctsDeploy'

* changed name

* remove space

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

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-05-18 21:39:35 +02:00

111 lines
2.5 KiB
Go

package cmd
import (
"github.com/stretchr/testify/assert"
"testing"
)
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, 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, nil, &httpClient)
assert.EqualError(t, err, "a http error occurred")
})
}