mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-30 05:59:39 +02:00
fix(whitesourceExecuteScan): respect versioning model and custom scan version (#4187)
* Test * Test * Test * Respect customScanVersion if filled * Add test case * Clean up * Respect versioningModel * Add test case * Clean up * Clean up
This commit is contained in:
parent
d1f3e2fc53
commit
8071337a44
@ -321,8 +321,13 @@ func createWhiteSourceProduct(config *ScanOptions, sys whitesource) (string, err
|
||||
|
||||
func resolveProjectIdentifiers(config *ScanOptions, scan *ws.Scan, utils whitesourceUtils, sys whitesource) error {
|
||||
if len(scan.AggregateProjectName) > 0 && (len(config.Version)+len(config.CustomScanVersion) > 0) {
|
||||
if config.Version == "" {
|
||||
if len(config.CustomScanVersion) > 0 {
|
||||
log.Entry().Infof("Using custom version: %v", config.CustomScanVersion)
|
||||
config.Version = config.CustomScanVersion
|
||||
} else if len(config.Version) > 0 {
|
||||
log.Entry().Infof("Resolving product version from default provided '%s' with versioning '%s'", config.Version, config.VersioningModel)
|
||||
config.Version = versioning.ApplyVersioningModel(config.VersioningModel, config.Version)
|
||||
log.Entry().Infof("Resolved product version '%s'", config.Version)
|
||||
}
|
||||
} else {
|
||||
options := &versioning.Options{
|
||||
|
@ -312,6 +312,49 @@ func TestResolveProjectIdentifiers(t *testing.T) {
|
||||
assert.Equal(t, "m2/path", utilsMock.usedOptions.M2Path)
|
||||
}
|
||||
})
|
||||
t.Run("success - with custom scan version (projectName is filled)", func(t *testing.T) {
|
||||
// init
|
||||
config := ScanOptions{
|
||||
BuildTool: "mta",
|
||||
CustomScanVersion: "latest",
|
||||
VersioningModel: "major",
|
||||
ProductName: "mock-product",
|
||||
ProjectName: "mock-project",
|
||||
Version: "0.0.1",
|
||||
}
|
||||
utilsMock := newWhitesourceUtilsMock()
|
||||
systemMock := ws.NewSystemMock("ignored")
|
||||
scan := newWhitesourceScan(&config)
|
||||
// test
|
||||
err := resolveProjectIdentifiers(&config, scan, utilsMock, systemMock)
|
||||
// assert
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, "mock-project", scan.AggregateProjectName)
|
||||
assert.Equal(t, "latest", config.Version)
|
||||
assert.Equal(t, "mock-product-token", config.ProductToken)
|
||||
}
|
||||
})
|
||||
t.Run("success - with version from default (projectName is filled)", func(t *testing.T) {
|
||||
// init
|
||||
config := ScanOptions{
|
||||
BuildTool: "mta",
|
||||
VersioningModel: "major-minor",
|
||||
ProductName: "mock-product",
|
||||
ProjectName: "mock-project",
|
||||
Version: "1.2.3",
|
||||
}
|
||||
utilsMock := newWhitesourceUtilsMock()
|
||||
systemMock := ws.NewSystemMock("ignored")
|
||||
scan := newWhitesourceScan(&config)
|
||||
// test
|
||||
err := resolveProjectIdentifiers(&config, scan, utilsMock, systemMock)
|
||||
// assert
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, "mock-project", scan.AggregateProjectName)
|
||||
assert.Equal(t, "1.2", config.Version)
|
||||
assert.Equal(t, "mock-product-token", config.ProductToken)
|
||||
}
|
||||
})
|
||||
t.Run("retrieves token for configured project name", func(t *testing.T) {
|
||||
// init
|
||||
config := ScanOptions{
|
||||
|
Loading…
x
Reference in New Issue
Block a user