mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
b81b11ca9d
* Unit Test Assemble Package * Remove obsolete lines dust wiping * climate change * climate change #2 * climate change #3 * climate change #4 * climate change #5 * NSPC serial builds * Actual Delivery Commit * Download Delivery_logs.zip * Publish Result * Testing * !Polling * Provide Commit to BF only if set * dust wiping * More Dust to Wipe * Publish more than on file * Write Log for Publish * fix unit test (now Dummy Entries) * save one line of code for climate change * Update cmd/abapEnvironmentAssemblePackages.go Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> * More Detailed Log Messages Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
165 lines
4.5 KiB
Go
165 lines
4.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
abapbuild "github.com/SAP/jenkins-library/pkg/abap/build"
|
|
"github.com/SAP/jenkins-library/pkg/abaputils"
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func testSetup(client piperhttp.Sender, buildID string) abapbuild.Build {
|
|
conn := new(abapbuild.Connector)
|
|
conn.Client = client
|
|
conn.DownloadClient = &abapbuild.DownloadClientMock{}
|
|
conn.Header = make(map[string][]string)
|
|
b := abapbuild.Build{
|
|
Connector: *conn,
|
|
BuildID: buildID,
|
|
}
|
|
return b
|
|
}
|
|
|
|
func TestCheckIfFailedAndPrintLogsWithError(t *testing.T) {
|
|
t.Run("checkIfFailedAndPrintLogs with failed build", func(t *testing.T) {
|
|
var repo abaputils.Repository
|
|
b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
|
|
b.RunState = abapbuild.Failed
|
|
var buildsWithRepo []buildWithRepository
|
|
bWR := buildWithRepository{
|
|
build: b,
|
|
repo: repo,
|
|
}
|
|
buildsWithRepo = append(buildsWithRepo, bWR)
|
|
err := checkIfFailedAndPrintLogs(buildsWithRepo)
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
t.Run("checkIfFailedAndPrintLogs", func(t *testing.T) {
|
|
var repo abaputils.Repository
|
|
b := testSetup(&abapbuild.ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
|
|
b.RunState = abapbuild.Finished
|
|
var buildsWithRepo []buildWithRepository
|
|
bWR := buildWithRepository{
|
|
build: b,
|
|
repo: repo,
|
|
}
|
|
buildsWithRepo = append(buildsWithRepo, bWR)
|
|
err := checkIfFailedAndPrintLogs(buildsWithRepo)
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestStartingInvalidInput(t *testing.T) {
|
|
t.Run("Run starting with Invalid Input", func(t *testing.T) {
|
|
client := &abapbuild.ClMock{
|
|
Token: "MyToken",
|
|
}
|
|
conn := new(abapbuild.Connector)
|
|
conn.Client = client
|
|
conn.Header = make(map[string][]string)
|
|
var repos []abaputils.Repository
|
|
repo := abaputils.Repository{
|
|
Name: "RepoA",
|
|
Status: "P",
|
|
}
|
|
repos = append(repos, repo)
|
|
builds, err := executeBuilds(repos, *conn, time.Duration(0*time.Second), time.Duration(1*time.Millisecond))
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, 1, len(builds))
|
|
assert.Equal(t, abapbuild.Failed, builds[0].build.RunState)
|
|
})
|
|
}
|
|
|
|
func TestStep(t *testing.T) {
|
|
autils := &abaputils.AUtilsMock{
|
|
ReturnedConnectionDetailsHTTP: abaputils.ConnectionDetailsHTTP{
|
|
URL: `/sap/opu/odata/BUILD/CORE_SRV`,
|
|
},
|
|
}
|
|
client := abapbuild.GetBuildMockClient()
|
|
cpe := &abapEnvironmentAssemblePackagesCommonPipelineEnvironment{}
|
|
|
|
t.Run("abapEnvironmentAssemblePackages: nothing to do", func(t *testing.T) {
|
|
|
|
config := &abapEnvironmentAssemblePackagesOptions{
|
|
AddonDescriptor: cpeAbapAddonDescriptorPackageLocked,
|
|
MaxRuntimeInMinutes: 1,
|
|
PollIntervalsInMilliseconds: 1,
|
|
}
|
|
|
|
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
|
|
assert.NoError(t, err)
|
|
})
|
|
t.Run("abapEnvironmentAssemblePackages: build", func(t *testing.T) {
|
|
|
|
config := &abapEnvironmentAssemblePackagesOptions{
|
|
AddonDescriptor: cpeAbapAddonDescriptorPackageReserved,
|
|
MaxRuntimeInMinutes: 1,
|
|
PollIntervalsInMilliseconds: 1,
|
|
}
|
|
|
|
err := runAbapEnvironmentAssemblePackages(config, nil, autils, &client, cpe)
|
|
assert.NoError(t, err)
|
|
assert.Contains(t, cpe.abap.addonDescriptor, `SAPK-001AAINITAPC1.SAR`)
|
|
})
|
|
}
|
|
|
|
var cpeAbapAddonDescriptorPackageLocked = `{
|
|
"addonProduct":"/ITAPC1/I_CURRENCZPRODUCT",
|
|
"addonVersion":"1.0.0",
|
|
"addonVersionAAK":"0001",
|
|
"addonUniqueID":"myAddonId",
|
|
"customerID":"$ID",
|
|
"AddonSpsLevel":"0000",
|
|
"AddonPatchLevel":"0000",
|
|
"TargetVectorID":"",
|
|
"repositories":[
|
|
{ "name":"/ITAPC1/I_CURRENCZ",
|
|
"tag":"whatever",
|
|
"branch":"",
|
|
"commitID":"",
|
|
"version":"1.0.0",
|
|
"versionAAK":"0001",
|
|
"PackageName":"SAPK-002AAINITAPC1",
|
|
"PackageType":"AOI",
|
|
"SpLevel":"0000",
|
|
"PatchLevel":"0000",
|
|
"PredecessorCommitID":"",
|
|
"Status":"L",
|
|
"Namespace":"/ITAPC1/",
|
|
"SarXMLFilePath":".pipeline\\commonPipelineEnvironment\\abap\\SAPK-002AAINITAPC1.SAR"
|
|
}
|
|
]
|
|
}`
|
|
|
|
var cpeAbapAddonDescriptorPackageReserved = `{
|
|
"addonProduct":"/ITAPC1/I_CURRENCZPRODUCT",
|
|
"addonVersion":"1.0.0",
|
|
"addonVersionAAK":"0001",
|
|
"addonUniqueID":"myAddonId",
|
|
"customerID":"$ID",
|
|
"AddonSpsLevel":"0000",
|
|
"AddonPatchLevel":"0000",
|
|
"TargetVectorID":"",
|
|
"repositories":[
|
|
{ "name":"/ITAPC1/I_CURRENCZ",
|
|
"tag":"whatever",
|
|
"branch":"",
|
|
"commitID":"",
|
|
"version":"1.0.0",
|
|
"versionAAK":"0001",
|
|
"PackageName":"SAPK-002AAINITAPC1",
|
|
"PackageType":"AOI",
|
|
"SpLevel":"0000",
|
|
"PatchLevel":"0000",
|
|
"PredecessorCommitID":"",
|
|
"Status":"P",
|
|
"Namespace":"/ITAPC1/",
|
|
"SarXMLFilePath":""
|
|
}
|
|
]
|
|
}`
|