1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/pkg/abaputils/manageGitRepositoryUtils_test.go
MuellerHenrik 164327667c
Add step abapEnvironmentCheckoutBranch (#1832)
* Add abaputils pkg and go files

* Add ReadServiceKeyAbapEnvironment function

* Fixes

* Add structs for SC, Pull and Branch

* Minor Improvements

* Adapt unit tests to new abaputils pkg

* Fixes

* Add adapted tests

* Fixes

* Fix cloudfoundry test

* Add check for host prefix (HTTPS)

* Fix tests + cleanup

* Fixes

* Fixes

* Fix

* Add mock for abaputils pkg unit tests

* Adapt abaputils comments

* Add abapEnvironmentCheckoutBranch step setup

* Change description of abapEnvCheckoutBranch step

* Add http client code

* Disable code due to missing interace

* Add coding for use of abaputils

* Adapt checkout branch step

* Adapt URL for checkout_branch function import

* Fixes

* Add unit test for missing params case

* Fix for missing mapping of CfSpace

* Fix for missing mapping of CfSpace

* Add working code for a Branch Checkout

* Fix host schema

* Remove LogoutOption param of unit tests and steps

* Fix unit test

* Fix unit test CF ReadServiceKey

* Add abapEnvironmentCheckoutBranch step setup

* Change description of abapEnvCheckoutBranch step

* Add http client code

* Disable code due to missing interace

* Add coding for use of abaputils

* Adapt checkout branch step

* Adapt URL for checkout_branch function import

* Fixes

* Fix for missing mapping of CfSpace

* Add working code for a Branch Checkout

* Adapt changes of abautils pkg

* Add test for polling

* Minor fix

* Fix yaml spacing

* Add longdescription to yaml

* Refactor abaputil methods

* Refactoring

* Refactoring

* Minor fix

* Minor fixeds

* Adapt to new abaputils.AUtilsMock

* Delete obsolete initial checks for params

* Fix manageGitRepoUtils_test.go

* Adjust pollEntity tests

Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
2020-08-04 17:52:28 +02:00

83 lines
1.9 KiB
Go

package abaputils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPollEntity(t *testing.T) {
t.Run("Test poll entity - success case", func(t *testing.T) {
client := &ClientMock{
BodyList: []string{
`{"d" : { "status" : "S" } }`,
`{"d" : { "status" : "R" } }`,
},
Token: "myToken",
StatusCode: 200,
}
options := AbapEnvironmentOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
CfServiceInstance: "testInstance",
CfServiceKeyName: "testServiceKey",
Username: "testUser",
Password: "testPassword",
}
config := AbapEnvironmentCheckoutBranchOptions{
AbapEnvOptions: options,
RepositoryName: "testRepo1",
}
con := ConnectionDetailsHTTP{
User: "MY_USER",
Password: "MY_PW",
URL: "https://api.endpoint.com/Entity/",
XCsrfToken: "MY_TOKEN",
}
status, _ := PollEntity(config.RepositoryName, con, client, 0)
assert.Equal(t, "S", status)
})
t.Run("Test poll entity - error case", func(t *testing.T) {
client := &ClientMock{
BodyList: []string{
`{"d" : { "status" : "E" } }`,
`{"d" : { "status" : "R" } }`,
},
Token: "myToken",
StatusCode: 200,
}
options := AbapEnvironmentOptions{
CfAPIEndpoint: "https://api.endpoint.com",
CfOrg: "testOrg",
CfSpace: "testSpace",
CfServiceInstance: "testInstance",
CfServiceKeyName: "testServiceKey",
Username: "testUser",
Password: "testPassword",
}
config := AbapEnvironmentCheckoutBranchOptions{
AbapEnvOptions: options,
RepositoryName: "testRepo1",
}
con := ConnectionDetailsHTTP{
User: "MY_USER",
Password: "MY_PW",
URL: "https://api.endpoint.com/Entity/",
XCsrfToken: "MY_TOKEN",
}
status, _ := PollEntity(config.RepositoryName, con, client, 0)
assert.Equal(t, "E", status)
})
}