You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
A unit (#3385)
* change return after files are persisted & Change logging * reduce object set to single object * adapt tests * adapt docu * adapt stage docu * adapt tests
This commit is contained in:
@@ -195,9 +195,6 @@ func buildAUnitTestBody(AUnitConfig AUnitConfig) (metadataString string, options
|
||||
if reflect.DeepEqual(ObjectSet{}, AUnitConfig.ObjectSet) {
|
||||
return "", "", "", fmt.Errorf("Error while parsing AUnit test run object set config. No object set has been provided. Please configure the objects you want to be checked for the respective test run")
|
||||
}
|
||||
if len(AUnitConfig.ObjectSet) == 0 {
|
||||
return "", "", "", fmt.Errorf("Error while parsing AUnit test run object set config. No object set has been provided. Please configure the set of objects you want to be checked for the respective test run")
|
||||
}
|
||||
|
||||
//Build Options
|
||||
optionsString += buildAUnitOptionsString(AUnitConfig)
|
||||
@@ -330,35 +327,34 @@ func writeObjectSetProperties(set MultiPropertySet) (objectSetString string) {
|
||||
func buildAUnitObjectSetString(AUnitConfig AUnitConfig) (objectSetString string) {
|
||||
|
||||
//Build ObjectSets
|
||||
for _, s := range AUnitConfig.ObjectSet {
|
||||
if s.Type == "" {
|
||||
s.Type = "multiPropertySet"
|
||||
s := AUnitConfig.ObjectSet
|
||||
if s.Type == "" {
|
||||
s.Type = "multiPropertySet"
|
||||
}
|
||||
if s.Type != "multiPropertySet" {
|
||||
log.Entry().Infof("Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information", s.Type)
|
||||
} else {
|
||||
objectSetString += `<osl:objectSet xsi:type="` + s.Type + `" xmlns:osl="http://www.sap.com/api/osl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">`
|
||||
|
||||
if !(reflect.DeepEqual(s.PackageNames, AUnitPackage{})) || !(reflect.DeepEqual(s.SoftwareComponents, SoftwareComponents{})) {
|
||||
//To ensure Scomps and packages can be assigned on this level
|
||||
mps := MultiPropertySet{
|
||||
PackageNames: s.PackageNames,
|
||||
SoftwareComponents: s.SoftwareComponents,
|
||||
}
|
||||
objectSetString += buildOSLObjectSets(mps)
|
||||
}
|
||||
if s.Type != "multiPropertySet" {
|
||||
log.Entry().Infof("Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information", s.Type)
|
||||
} else {
|
||||
objectSetString += `<osl:objectSet xsi:type="` + s.Type + `" xmlns:osl="http://www.sap.com/api/osl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">`
|
||||
|
||||
if !(reflect.DeepEqual(s.PackageNames, AUnitPackage{})) || !(reflect.DeepEqual(s.SoftwareComponents, SoftwareComponents{})) {
|
||||
//To ensure Scomps and packages can be assigned on this level
|
||||
mps := MultiPropertySet{
|
||||
PackageNames: s.PackageNames,
|
||||
SoftwareComponents: s.SoftwareComponents,
|
||||
}
|
||||
objectSetString += buildOSLObjectSets(mps)
|
||||
}
|
||||
objectSetString += buildOSLObjectSets(s.MultiPropertySet)
|
||||
|
||||
objectSetString += buildOSLObjectSets(s.MultiPropertySet)
|
||||
|
||||
if !(reflect.DeepEqual(s.MultiPropertySet, MultiPropertySet{})) {
|
||||
log.Entry().Info("Wrong configuration has been detected: MultiPropertySet has been used. Please note that there is no official documentation for this usage. Please check the step documentation for more information")
|
||||
}
|
||||
|
||||
for _, t := range s.Set {
|
||||
log.Entry().Infof("Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information", t.Type)
|
||||
}
|
||||
objectSetString += `</osl:objectSet>`
|
||||
if !(reflect.DeepEqual(s.MultiPropertySet, MultiPropertySet{})) {
|
||||
log.Entry().Info("Wrong configuration has been detected: MultiPropertySet has been used. Please note that there is no official documentation for this usage. Please check the step documentation for more information")
|
||||
}
|
||||
|
||||
for _, t := range s.Set {
|
||||
log.Entry().Infof("Wrong configuration has been detected: %s has been used. This is currently not supported and this set will not be included in this run. Please check the step documentation for more information", t.Type)
|
||||
}
|
||||
objectSetString += `</osl:objectSet>`
|
||||
}
|
||||
return objectSetString
|
||||
}
|
||||
@@ -535,7 +531,7 @@ type AUnitConfig struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Context string `json:"context,omitempty"`
|
||||
Options AUnitOptions `json:"options,omitempty"`
|
||||
ObjectSet []ObjectSet `json:"objectset,omitempty"`
|
||||
ObjectSet ObjectSet `json:"objectset,omitempty"`
|
||||
}
|
||||
|
||||
//AUnitOptions in form of packages and software components to be checked
|
||||
|
||||
@@ -79,99 +79,33 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
Long: new(bool),
|
||||
},
|
||||
},
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
Type: "testSet",
|
||||
Set: []Set{
|
||||
{
|
||||
Type: "testSet",
|
||||
Set: []Set{
|
||||
{
|
||||
Type: "testAUnitFlatObjectSet",
|
||||
FlatObjectSet: []AUnitFlatObjectSet{
|
||||
{
|
||||
Name: "TestCLAS",
|
||||
Type: "CLAS",
|
||||
},
|
||||
{
|
||||
Name: "TestINTF",
|
||||
Type: "INTF",
|
||||
}},
|
||||
},
|
||||
{
|
||||
Type: "testAUnitObjectTypeSet",
|
||||
ObjectTypeSet: []AUnitObjectTypeSet{
|
||||
{
|
||||
Name: "TestObjectType",
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
}
|
||||
ObjectSet: ObjectSet{
|
||||
|
||||
var metadataString, optionsString, objectSetString string
|
||||
|
||||
metadataString, optionsString, objectSetString, err = buildAUnitTestBody(config)
|
||||
|
||||
assert.Equal(t, expectedmetadataString, metadataString)
|
||||
assert.Equal(t, expectedoptionsString, optionsString)
|
||||
assert.Equal(t, expectedobjectSetString, objectSetString)
|
||||
assert.Equal(t, nil, err)
|
||||
})
|
||||
|
||||
t.Run("Test AUnit test run body with example yaml config of Multi Property Set and not supported Objects Sets combined", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expectedmetadataString := `<aunit:run title="Test Title" context="Test Context" xmlns:aunit="http://www.sap.com/adt/api/aunit">`
|
||||
expectedoptionsString := `<aunit:options><aunit:measurements type="none"/><aunit:scope ownTests="false" foreignTests="false"/><aunit:riskLevel harmless="false" dangerous="false" critical="false"/><aunit:duration short="false" medium="false" long="false"/></aunit:options>`
|
||||
//Ensure that each Set besides MPS will be empty. Full empty object sets can be send via the XML request body, they simply do nothing
|
||||
expectedobjectSetString := `<osl:objectSet xsi:type="multiPropertySet" xmlns:osl="http://www.sap.com/api/osl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><osl:softwareComponent name="testComponent1"/><osl:softwareComponent name="testComponent2"/></osl:objectSet></aunit:run>`
|
||||
|
||||
var err error
|
||||
var config AUnitConfig
|
||||
|
||||
config = AUnitConfig{
|
||||
Title: "Test Title",
|
||||
Context: "Test Context",
|
||||
Options: AUnitOptions{
|
||||
Measurements: "none",
|
||||
Scope: Scope{
|
||||
OwnTests: new(bool),
|
||||
ForeignTests: new(bool),
|
||||
},
|
||||
RiskLevel: RiskLevel{
|
||||
Harmless: new(bool),
|
||||
Dangerous: new(bool),
|
||||
Critical: new(bool),
|
||||
},
|
||||
Duration: Duration{
|
||||
Short: new(bool),
|
||||
Medium: new(bool),
|
||||
Long: new(bool),
|
||||
},
|
||||
},
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
Type: "testSet",
|
||||
Set: []Set{
|
||||
{
|
||||
Type: "testBaseSet",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: "multiPropertySet",
|
||||
MultiPropertySet: MultiPropertySet{
|
||||
SoftwareComponents: []SoftwareComponents{
|
||||
Type: "testSet",
|
||||
Set: []Set{
|
||||
{
|
||||
Type: "testSet",
|
||||
Set: []Set{
|
||||
{
|
||||
Name: "testComponent1",
|
||||
Type: "testAUnitFlatObjectSet",
|
||||
FlatObjectSet: []AUnitFlatObjectSet{
|
||||
{
|
||||
Name: "TestCLAS",
|
||||
Type: "CLAS",
|
||||
},
|
||||
{
|
||||
Name: "TestINTF",
|
||||
Type: "INTF",
|
||||
}},
|
||||
},
|
||||
{
|
||||
Name: "testComponent2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Type: "testAUnitObjectTypeSet",
|
||||
ObjectTypeSet: []AUnitObjectTypeSet{
|
||||
{
|
||||
Name: "TestObjectType",
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -215,17 +149,15 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
Long: new(bool),
|
||||
},
|
||||
},
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
Type: "multiPropertySet",
|
||||
MultiPropertySet: MultiPropertySet{
|
||||
SoftwareComponents: []SoftwareComponents{
|
||||
{
|
||||
Name: "testComponent1",
|
||||
},
|
||||
{
|
||||
Name: "testComponent2",
|
||||
},
|
||||
ObjectSet: ObjectSet{
|
||||
Type: "multiPropertySet",
|
||||
MultiPropertySet: MultiPropertySet{
|
||||
SoftwareComponents: []SoftwareComponents{
|
||||
{
|
||||
Name: "testComponent1",
|
||||
},
|
||||
{
|
||||
Name: "testComponent2",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -272,17 +204,15 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
Long: new(bool),
|
||||
},
|
||||
},
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
Type: "",
|
||||
MultiPropertySet: MultiPropertySet{
|
||||
SoftwareComponents: []SoftwareComponents{
|
||||
{
|
||||
Name: "testComponent1",
|
||||
},
|
||||
{
|
||||
Name: "testComponent2",
|
||||
},
|
||||
ObjectSet: ObjectSet{
|
||||
Type: "",
|
||||
MultiPropertySet: MultiPropertySet{
|
||||
SoftwareComponents: []SoftwareComponents{
|
||||
{
|
||||
Name: "testComponent1",
|
||||
},
|
||||
{
|
||||
Name: "testComponent2",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -329,19 +259,17 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
Long: new(bool),
|
||||
},
|
||||
},
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}, {
|
||||
Name: "testPackage2",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}, {
|
||||
Name: "testComponent2",
|
||||
}},
|
||||
},
|
||||
ObjectSet: ObjectSet{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}, {
|
||||
Name: "testPackage2",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}, {
|
||||
Name: "testComponent2",
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -388,15 +316,13 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
var config AUnitConfig
|
||||
|
||||
config = AUnitConfig{Title: "Test",
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}},
|
||||
},
|
||||
ObjectSet: ObjectSet{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}},
|
||||
}}
|
||||
|
||||
var metadataString, optionsString, objectSetString string
|
||||
@@ -420,15 +346,13 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
var config AUnitConfig
|
||||
|
||||
config = AUnitConfig{Title: "Test", Context: "Test",
|
||||
ObjectSet: []ObjectSet{
|
||||
{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}},
|
||||
},
|
||||
ObjectSet: ObjectSet{
|
||||
PackageNames: []AUnitPackage{{
|
||||
Name: "testPackage1",
|
||||
}},
|
||||
SoftwareComponents: []SoftwareComponents{{
|
||||
Name: "testComponent1",
|
||||
}},
|
||||
}}
|
||||
|
||||
var metadataString, optionsString, objectSetString string
|
||||
@@ -460,7 +384,7 @@ func TestBuildAUnitTestBody(t *testing.T) {
|
||||
assert.Equal(t, expectedmetadataString, metadataString)
|
||||
assert.Equal(t, expectedoptionsString, optionsString)
|
||||
assert.Equal(t, expectedobjectSetString, objectSetString)
|
||||
assert.EqualError(t, err, "Error while parsing AUnit test run object set config. No object set has been provided. Please configure the set of objects you want to be checked for the respective test run")
|
||||
assert.EqualError(t, err, "Error while parsing AUnit test run object set config. No object set has been provided. Please configure the objects you want to be checked for the respective test run")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -512,7 +436,7 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectset:
|
||||
- packages:
|
||||
packages:
|
||||
- name: Z_TEST
|
||||
softwarecomponents:
|
||||
- name: Z_TEST
|
||||
@@ -570,13 +494,11 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectset:
|
||||
- type: unionSet
|
||||
type: unionSet
|
||||
set:
|
||||
- type: componentSet
|
||||
component:
|
||||
- name: Z_TEST_SC
|
||||
- packages:
|
||||
- name: Z_TEST_PACKAGE2
|
||||
`
|
||||
|
||||
err = ioutil.WriteFile(config.AUnitConfig, []byte(yamlBody), 0644)
|
||||
|
||||
@@ -125,7 +125,7 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectSet:
|
||||
- softwarecomponents:
|
||||
- name: Z_TEST_SC
|
||||
- name: Z_TEST_SC2
|
||||
softwarecomponents:
|
||||
- name: Z_TEST_SC
|
||||
- name: Z_TEST_SC2
|
||||
```
|
||||
|
||||
@@ -97,8 +97,8 @@ See below example for an `aUnitConfig.yml` file containing a minimal configurati
|
||||
title: My AUnit run
|
||||
context: My unit tests
|
||||
objectset:
|
||||
- softwareComponents:
|
||||
- name: /DMO/SWC
|
||||
softwareComponents:
|
||||
- name: /DMO/SWC
|
||||
```
|
||||
|
||||
See below example for an `aUnitConfig.yml` file with the configured options containing the package `Z_TEST_PACKAGE` to be checked:
|
||||
@@ -120,8 +120,8 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectset:
|
||||
- packages:
|
||||
- name: Z_TEST_PACKAGE
|
||||
packages:
|
||||
- name: Z_TEST_PACKAGE
|
||||
```
|
||||
|
||||
The following example of an `aUnitConfig.yml` file containing the software component `Z_TESTSC` to be checked:
|
||||
@@ -143,8 +143,8 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectset:
|
||||
- softwarecomponents:
|
||||
- name: Z_TESTSC
|
||||
softwarecomponents:
|
||||
- name: Z_TESTSC
|
||||
```
|
||||
|
||||
The following example of an `aUnitConfig.yml` file contains all possible properties of the Multi Property Set that can be used. Please take note that this is not the reccommended approach. If you want to check packages or software components please use the two above examples. The usage of the Multi Property Set is only reccommended for ABAP Unit tests that require these rules for the test execution. There is no official documentation on the usage of the Multi Property Set.
|
||||
@@ -166,32 +166,32 @@ options:
|
||||
medium: true
|
||||
long: true
|
||||
objectset:
|
||||
- type: multiPropertySet
|
||||
multipropertyset:
|
||||
owner:
|
||||
- name: demoOwner
|
||||
softwarecomponents:
|
||||
type: multiPropertySet
|
||||
multipropertyset:
|
||||
owner:
|
||||
- name: demoOwner
|
||||
softwarecomponents:
|
||||
- component:
|
||||
name: demoSoftwareComponent
|
||||
version:
|
||||
- value: ACTIVE
|
||||
packages:
|
||||
- package:
|
||||
name: demoPackage
|
||||
objectnamepattern:
|
||||
- value: 'ZCL_*'
|
||||
language:
|
||||
- value: EN
|
||||
sourcesystem:
|
||||
- name: H01
|
||||
objecttype:
|
||||
- name: CLAS
|
||||
objecttypegroup:
|
||||
- name: CLAS
|
||||
releasestate:
|
||||
- value: RELEASED
|
||||
applicationcomponent:
|
||||
- name: demoApplicationComponent
|
||||
transportlayer:
|
||||
- name: H01
|
||||
name: demoSoftwareComponent
|
||||
version:
|
||||
- value: ACTIVE
|
||||
packages:
|
||||
- package:
|
||||
name: demoPackage
|
||||
objectnamepattern:
|
||||
- value: 'ZCL_*'
|
||||
language:
|
||||
- value: EN
|
||||
sourcesystem:
|
||||
- name: H01
|
||||
objecttype:
|
||||
- name: CLAS
|
||||
objecttypegroup:
|
||||
- name: CLAS
|
||||
releasestate:
|
||||
- value: RELEASED
|
||||
applicationcomponent:
|
||||
- name: demoApplicationComponent
|
||||
transportlayer:
|
||||
- name: H01
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user