mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-21 19:48:53 +02:00
Parallel test processing for abaputils (#2570)
* add parallel test processing * Add more t.Parallel * add parallel to run * Remove obsolete parallel statements
This commit is contained in:
parent
a104b2a06d
commit
e6086ad4a7
@ -11,8 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func TestCheckoutBranchStep(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Run Step Successful - repositoryName and branchName config", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
@ -46,6 +47,7 @@ func TestCheckoutBranchStep(t *testing.T) {
|
||||
assert.NoError(t, err, "Did not expect error")
|
||||
})
|
||||
t.Run("Run Step Failure - empty config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedErrorMessage := "Something failed during the checkout: Checking configuration failed: You have not specified any repository or branch configuration to be checked out in the ABAP Environment System. Please make sure that you specified the repositories with their branches that should be checked out either in a dedicated file or via the parameters 'repositoryName' and 'branchName'. For more information please read the User documentation"
|
||||
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
@ -71,6 +73,7 @@ func TestCheckoutBranchStep(t *testing.T) {
|
||||
assert.EqualError(t, err, expectedErrorMessage)
|
||||
})
|
||||
t.Run("Run Step Failure - wrong status", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedErrorMessage := "Something failed during the checkout: Checkout failed: Checkout of branch testBranch failed on the ABAP System"
|
||||
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
@ -259,8 +262,9 @@ repositories:
|
||||
}
|
||||
|
||||
func TestTriggerCheckout(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Test trigger checkout: success case", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
// given
|
||||
receivedURI := "example.com/Branches"
|
||||
uriExpected := receivedURI + "?$expand=to_Execution_log,to_Transport_log"
|
||||
@ -297,7 +301,7 @@ func TestTriggerCheckout(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Test trigger checkout: ABAP Error case", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
// given
|
||||
errorMessage := "ABAP Error Message"
|
||||
errorCode := "ERROR/001"
|
||||
@ -336,7 +340,9 @@ func TestTriggerCheckout(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCheckoutConfigChecker(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Success case: check config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abapEnvironmentCheckoutBranchOptions{
|
||||
RepositoryName: "testRepo1",
|
||||
BranchName: "feature-unit-test",
|
||||
@ -345,6 +351,7 @@ func TestCheckoutConfigChecker(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("Success case: check file config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abapEnvironmentCheckoutBranchOptions{
|
||||
Repositories: "test.file",
|
||||
BranchName: "feature-unit-test",
|
||||
@ -353,6 +360,7 @@ func TestCheckoutConfigChecker(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("Failure case: check empty config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedErrorMessage := "Checking configuration failed: You have not specified any repository or branch configuration to be checked out in the ABAP Environment System. Please make sure that you specified the repositories with their branches that should be checked out either in a dedicated file or via the parameters 'repositoryName' and 'branchName'. For more information please read the User documentation"
|
||||
|
||||
config := abapEnvironmentCheckoutBranchOptions{}
|
||||
|
@ -119,7 +119,9 @@ repositories:
|
||||
}
|
||||
|
||||
func TestCloneStepErrorMessages(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Status Error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
@ -178,6 +180,7 @@ repositories:
|
||||
})
|
||||
|
||||
t.Run("Poll Request Error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
@ -214,6 +217,7 @@ repositories:
|
||||
})
|
||||
|
||||
t.Run("Trigger Clone Error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
@ -249,6 +253,7 @@ repositories:
|
||||
})
|
||||
|
||||
t.Run("Missing file error", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
func TestPullStep(t *testing.T) {
|
||||
t.Run("Run Step Successful", func(t *testing.T) {
|
||||
|
||||
var autils = abaputils.AUtilsMock{}
|
||||
defer autils.Cleanup()
|
||||
autils.ReturnedConnectionDetailsHTTP.Password = "password"
|
||||
@ -345,9 +344,9 @@ repositories:
|
||||
}
|
||||
|
||||
func TestTriggerPull(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
t.Run("Test trigger pull: success case", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
receivedURI := "example.com/Entity"
|
||||
uriExpected := receivedURI + "?$expand=to_Execution_log,to_Transport_log"
|
||||
tokenExpected := "myToken"
|
||||
@ -373,7 +372,7 @@ func TestTriggerPull(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Test trigger pull: ABAP Error", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
errorMessage := "ABAP Error Message"
|
||||
errorCode := "ERROR/001"
|
||||
HTTPErrorMessage := "HTTP Error Message"
|
||||
@ -400,7 +399,9 @@ func TestTriggerPull(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPullConfigChecker(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Success case: check config file", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abapEnvironmentPullGitRepoOptions{
|
||||
Repositories: "test.file",
|
||||
}
|
||||
@ -408,6 +409,7 @@ func TestPullConfigChecker(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("Success case: check config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abapEnvironmentPullGitRepoOptions{
|
||||
RepositoryNames: []string{"testRepo", "testRepo2"},
|
||||
}
|
||||
@ -415,6 +417,7 @@ func TestPullConfigChecker(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("Failure case: empty config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
errorMessage := "Checking configuration failed: You have not specified any repository configuration to be pulled into the ABAP Environment System. Please make sure that you specified the repositories that should be pulled either in a dedicated file or via the parameter 'repositoryNames'. For more information please read the User documentation"
|
||||
config := abapEnvironmentPullGitRepoOptions{}
|
||||
err := checkPullRepositoryConfiguration(config)
|
||||
@ -423,7 +426,9 @@ func TestPullConfigChecker(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHelpFunctions(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Ignore Commit", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo1 := abaputils.Repository{
|
||||
Name: "Repo1",
|
||||
CommitID: "ABCD1234",
|
||||
@ -440,6 +445,7 @@ func TestHelpFunctions(t *testing.T) {
|
||||
assert.Equal(t, "", repoList[1].CommitID, "Expected emtpy CommitID")
|
||||
})
|
||||
t.Run("Not Ignore Commit", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
repo1 := abaputils.Repository{
|
||||
Name: "Repo1",
|
||||
CommitID: "ABCD1234",
|
||||
|
@ -11,7 +11,9 @@ import (
|
||||
)
|
||||
|
||||
func TestHostConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Check Host: ABAP Endpoint", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abaputils.AbapEnvironmentOptions{
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
@ -36,6 +38,7 @@ func TestHostConfig(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("No host/ServiceKey configuration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
//Testing without CfOrg parameter
|
||||
config := abaputils.AbapEnvironmentOptions{
|
||||
CfAPIEndpoint: "https://api.endpoint.com",
|
||||
@ -66,6 +69,7 @@ func TestHostConfig(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Check Host: CF Service Key", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := abaputils.AbapEnvironmentOptions{
|
||||
CfAPIEndpoint: "https://api.endpoint.com",
|
||||
CfSpace: "testSpace",
|
||||
@ -117,7 +121,9 @@ func TestATCTrigger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFetchXcsrfToken(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("FetchXcsrfToken Test", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tokenExpected := "myToken"
|
||||
|
||||
client := &abaputils.ClientMock{
|
||||
@ -136,6 +142,7 @@ func TestFetchXcsrfToken(t *testing.T) {
|
||||
}
|
||||
})
|
||||
t.Run("failure case: fetch token", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
tokenExpected := ""
|
||||
|
||||
client := &abaputils.ClientMock{
|
||||
@ -296,7 +303,9 @@ func TestParseATCResult(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuildATCCheckBody(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Test build body with no software component and package", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedpackagestring := ""
|
||||
expectedsoftwarecomponentstring := ""
|
||||
expectedcheckvariantstring := ""
|
||||
@ -313,6 +322,7 @@ func TestBuildATCCheckBody(t *testing.T) {
|
||||
assert.EqualError(t, err, "Error while parsing ATC run config. Please provide the packages and/or the software components to be checked! No Package or Software Component specified. Please provide either one or both of them")
|
||||
})
|
||||
t.Run("success case: Test build body with example yaml config", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedcheckvariantstring := " checkVariant=\"SAP_CLOUD_PLATFORM_ATC_DEFAULT\""
|
||||
expectedpackagestring := "<obj:packages><obj:package value=\"testPackage\" includeSubpackages=\"true\"/><obj:package value=\"testPackage2\" includeSubpackages=\"false\"/></obj:packages>"
|
||||
expectedsoftwarecomponentstring := "<obj:softwarecomponents><obj:softwarecomponent value=\"testSoftwareComponent\"/><obj:softwarecomponent value=\"testSoftwareComponent2\"/></obj:softwarecomponents>"
|
||||
@ -345,6 +355,7 @@ func TestBuildATCCheckBody(t *testing.T) {
|
||||
assert.Equal(t, nil, err)
|
||||
})
|
||||
t.Run("failure case: Test build body with example yaml config with only packages and no software components", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedcheckvariantstring := " checkVariant=\"SAP_CLOUD_PLATFORM_ATC_DEFAULT\""
|
||||
expectedpackagestring := `<obj:packages><obj:package value="testPackage" includeSubpackages="true"/><obj:package value="testPackage2" includeSubpackages="false"/></obj:packages>`
|
||||
expectedsoftwarecomponentstring := ""
|
||||
@ -374,6 +385,7 @@ func TestBuildATCCheckBody(t *testing.T) {
|
||||
|
||||
})
|
||||
t.Run("success case: Test build body with example yaml config with no packages and only software components", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedcheckvariantstring := " checkVariant=\"SAP_CLOUD_PLATFORM_ATC_DEFAULT\""
|
||||
expectedpackagestring := ""
|
||||
expectedsoftwarecomponentstring := `<obj:softwarecomponents><obj:softwarecomponent value="testSoftwareComponent"/><obj:softwarecomponent value="testSoftwareComponent2"/></obj:softwarecomponents>`
|
||||
@ -402,6 +414,7 @@ func TestBuildATCCheckBody(t *testing.T) {
|
||||
assert.Equal(t, nil, err)
|
||||
})
|
||||
t.Run("success case: Test build body with example yaml config with check variant configuration", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedcheckvariantstring := ` checkVariant="TestVariant" configuration="TestConfiguration"`
|
||||
expectedpackagestring := `<obj:packages><obj:package value="testPackage" includeSubpackages="true"/><obj:package value="testPackage2" includeSubpackages="false"/></obj:packages>`
|
||||
expectedsoftwarecomponentstring := `<obj:softwarecomponents><obj:softwarecomponent value="testSoftwareComponent"/><obj:softwarecomponent value="testSoftwareComponent2"/></obj:softwarecomponents>`
|
||||
|
@ -15,7 +15,9 @@ import (
|
||||
)
|
||||
|
||||
func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("CF GetAbapCommunicationArrangementInfo - Error - parameters missing", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
//given
|
||||
options := AbapEnvironmentOptions{
|
||||
@ -45,6 +47,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
|
||||
assert.EqualError(t, err, "Parameters missing. Please provide EITHER the Host of the ABAP server OR the Cloud Foundry ApiEndpoint, Organization, Space, Service Instance and a corresponding Service Key for the Communication Scenario SAP_COM_0510")
|
||||
})
|
||||
t.Run("CF GetAbapCommunicationArrangementInfo - Error - reading service Key", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
//given
|
||||
options := AbapEnvironmentOptions{
|
||||
CfAPIEndpoint: "https://api.endpoint.com",
|
||||
@ -73,7 +76,7 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
|
||||
assert.EqualError(t, err, "Read service key failed: Parsing the service key failed. Service key is empty")
|
||||
})
|
||||
t.Run("CF GetAbapCommunicationArrangementInfo - Success", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
//given
|
||||
|
||||
const testURL = "https://testurl.com"
|
||||
@ -115,8 +118,9 @@ func TestCloudFoundryGetAbapCommunicationInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHostGetAbapCommunicationInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("HOST GetAbapCommunicationArrangementInfo - Success", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
//given
|
||||
|
||||
const testURL = "https://testurl.com"
|
||||
@ -153,7 +157,7 @@ func TestHostGetAbapCommunicationInfo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("HOST GetAbapCommunicationArrangementInfo - Success - w/o https", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
//given
|
||||
|
||||
const testURL = "testurl.com"
|
||||
@ -192,8 +196,10 @@ func TestHostGetAbapCommunicationInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadServiceKeyAbapEnvironment(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("CF ReadServiceKeyAbapEnvironment - Failed to login to Cloud Foundry", func(t *testing.T) {
|
||||
//given .
|
||||
t.Parallel()
|
||||
//given
|
||||
options := AbapEnvironmentOptions{
|
||||
Username: "testUser",
|
||||
Password: "testPassword",
|
||||
@ -228,19 +234,23 @@ func TestReadServiceKeyAbapEnvironment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTimeConverter(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Test example time", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
inputDate := "/Date(1585576809000+0000)/"
|
||||
expectedDate := "2020-03-30 14:00:09 +0000 UTC"
|
||||
result := ConvertTime(inputDate)
|
||||
assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion")
|
||||
})
|
||||
t.Run("Test Unix time", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
inputDate := "/Date(0000000000000+0000)/"
|
||||
expectedDate := "1970-01-01 00:00:00 +0000 UTC"
|
||||
result := ConvertTime(inputDate)
|
||||
assert.Equal(t, expectedDate, result.String(), "Dates do not match after conversion")
|
||||
})
|
||||
t.Run("Test unexpected format", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
inputDate := "/Date(0012300000001+0000)/"
|
||||
expectedDate := "1970-01-01 00:00:00 +0000 UTC"
|
||||
result := ConvertTime(inputDate)
|
||||
@ -249,7 +259,9 @@ func TestTimeConverter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReadAddonDescriptor(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Test: success case", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir, err := ioutil.TempDir("", "test read addon descriptor")
|
||||
if err != nil {
|
||||
@ -303,6 +315,7 @@ repositories:
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
t.Run("Test: file does not exist", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedErrorMessage := "AddonDescriptor doesn't contain any repositories"
|
||||
|
||||
addonDescriptor, err := ReadAddonDescriptor("filename.yaml")
|
||||
@ -313,6 +326,7 @@ repositories:
|
||||
assert.EqualError(t, err, expectedErrorMessage)
|
||||
})
|
||||
t.Run("Test: empty config - failure case", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedErrorMessage := "AddonDescriptor doesn't contain any repositories"
|
||||
|
||||
addonDescriptor, err := ReadAddonDescriptor("")
|
||||
@ -358,8 +372,9 @@ repositories:
|
||||
}
|
||||
|
||||
func TestHandleHTTPError(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Test", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
errorValue := "Received Error"
|
||||
abapErrorCode := "abapErrorCode"
|
||||
abapErrorMessage := "abapErrorMessage"
|
||||
@ -380,7 +395,7 @@ func TestHandleHTTPError(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Non JSON Error", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
errorValue := "Received Error"
|
||||
bodyString := `Error message`
|
||||
body := []byte(bodyString)
|
||||
@ -399,7 +414,7 @@ func TestHandleHTTPError(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Different JSON Error", func(t *testing.T) {
|
||||
|
||||
t.Parallel()
|
||||
errorValue := "Received Error"
|
||||
bodyString := `{"abap" : { "key" : "value" } }`
|
||||
body := []byte(bodyString)
|
||||
|
Loading…
x
Reference in New Issue
Block a user