Skip to content

Commit

Permalink
[tmsUpload] Use Golang implementation of the step by default (SAP#4535)
Browse files Browse the repository at this point in the history
* Use new Golang implementation of tmsUpload step by default
  • Loading branch information
artembannikov authored and maxatsap committed Jul 23, 2024
1 parent a4a8520 commit 80bf585
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
64 changes: 58 additions & 6 deletions test/groovy/TmsUploadTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import util.JenkinsReadYamlRule
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.not
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertThat
import static org.junit.Assert.assertTrue

public class TmsUploadTest extends BasePiperTest {

Expand Down Expand Up @@ -84,6 +86,42 @@ public class TmsUploadTest extends BasePiperTest {
calledTmsMethodsWithArgs.clear()
}

@Test
public void defaultUseGoStep__callsPiperExecuteBin() {
String calledStep = ''
String usedMetadataFile = ''
List credInfo = []
helper.registerAllowedMethod('piperExecuteBin', [Map, String, String, List], {
Map parameters, String stepName,
String metadataFile, List credentialInfo ->
calledStep = stepName
usedMetadataFile = metadataFile
credInfo = credentialInfo
})

jenkinsUtilsStub = new JenkinsUtilsMock("Test User")

stepRule.step.tmsUpload(
script: nullScript,
jenkinsUtilsStub: jenkinsUtilsStub,
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey'
)

assertEquals('tmsUpload', calledStep)
assertEquals('metadata/tmsUpload.yaml', usedMetadataFile)

// contains assertion does not work apparently when comparing a list of lists against an expected list
boolean found = false
credInfo.each { entry ->
if (entry == [type: 'token', id: 'credentialsId', env: ['PIPER_tmsServiceKey']]) {
found = true
}
}
assertTrue(found)
}

@Test
public void minimalConfig__isSuccessful() {
jenkinsUtilsStub = new JenkinsUtilsMock("Test User")
Expand All @@ -97,7 +135,8 @@ public class TmsUploadTest extends BasePiperTest {
transportManagementService: tmsStub,
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey'
credentialsId: 'TMS_ServiceKey',
useGoStep: false
)

assertThat(calledTmsMethodsWithArgs[0], is("authentication('${uaaUrl}', '${oauthClientId}', '${oauthClientSecret}')"))
Expand All @@ -123,9 +162,12 @@ public class TmsUploadTest extends BasePiperTest {
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey',
verbose: true
verbose: true,
useGoStep: false
)

assertThat(loggingRule.log, containsString("[TransportManagementService] Using deprecated Groovy implementation of 'tmsUpload' step instead of the default Golang one, since 'useGoStep' toggle parameter is explicitly set to 'false'."))
assertThat(loggingRule.log, containsString("[TransportManagementService] WARNING: Note that the deprecated Groovy implementation will be completely removed after February 29th, 2024. Consider using the Golang implementation by not setting the 'useGoStep' toggle parameter to 'false'."))
assertThat(loggingRule.log, containsString("[TransportManagementService] CredentialsId: 'TMS_ServiceKey'"))
assertThat(loggingRule.log, containsString("[TransportManagementService] Node name: 'myNode'"))
assertThat(loggingRule.log, containsString("[TransportManagementService] MTA path: 'dummy.mtar'"))
Expand All @@ -148,7 +190,8 @@ public class TmsUploadTest extends BasePiperTest {
transportManagementService: tmsStub,
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey'
credentialsId: 'TMS_ServiceKey',
useGoStep: false
)

assertThat(calledTmsMethodsWithArgs[1], is("uploadFile('${uri}', 'myToken', './dummy.mtar', 'Piper-Pipeline')"))
Expand All @@ -168,7 +211,8 @@ public class TmsUploadTest extends BasePiperTest {
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey',
customDescription: 'My custom description for testing.'
customDescription: 'My custom description for testing.',
useGoStep: false
)

assertThat(calledTmsMethodsWithArgs[2], is("uploadFileToNode('${uri}', 'myToken', 'myNode', '1234', 'My custom description for testing.')"))
Expand All @@ -193,6 +237,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '0.0.1',
useGoStep: false
)

assertThat(loggingRule.log, containsString("[TransportManagementService] MTA Extension Descriptor with ID 'com.sap.piper.tms.test.extension' successfully uploaded to Node 'testNode1'."))
Expand All @@ -219,6 +264,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '1.2.2',
useGoStep: false
)

assertThat(loggingRule.log, containsString("[TransportManagementService] MTA Extension Descriptor with ID 'com.sap.piper.tms.test.another.extension' successfully updated for Node 'testNode1'."))
Expand Down Expand Up @@ -249,6 +295,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '9.9.9',
useGoStep: false
)

assertThat(calledTmsMethodsWithArgs[2], is("getMtaExtDescriptor('${uri}', 'myToken', 1, 'com.sap.piper.tms.test', '9.9.9')"))
Expand All @@ -271,7 +318,8 @@ public class TmsUploadTest extends BasePiperTest {
mtaPath: 'dummy.mtar',
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey',
customDescription: 'My custom description for testing.'
customDescription: 'My custom description for testing.',
useGoStep: false
)
}

Expand All @@ -288,7 +336,8 @@ public class TmsUploadTest extends BasePiperTest {
jenkinsUtilsStub: jenkinsUtilsStub,
transportManagementService: tmsStub,
nodeName: 'myNode',
credentialsId: 'TMS_ServiceKey'
credentialsId: 'TMS_ServiceKey',
useGoStep: false
)

assertThat(calledTmsMethodsWithArgs[1], is("uploadFile('${uri}', 'myToken', './dummy.mtar', 'Test User')"))
Expand Down Expand Up @@ -316,6 +365,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '0.0.1',
useGoStep: false
)
}

Expand All @@ -340,6 +390,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '0.0.1',
useGoStep: false
)
}

Expand All @@ -365,6 +416,7 @@ public class TmsUploadTest extends BasePiperTest {
credentialsId: 'TMS_ServiceKey',
nodeExtDescriptorMapping: nodeExtDescriptorMap,
mtaVersion: '0.0.1',
useGoStep: false
)
}

Expand Down
7 changes: 5 additions & 2 deletions vars/tmsUpload.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import static com.sap.piper.Prerequisites.checkScript
*/
'proxy',
/**
* Toggle to activate a new Golang implementation of the step. Off by default.
* The new Golang implementation of the step is used now by default. Utilizing this toggle with value true is therefore redundant and can be omitted. If used with value false, the toggle deactivates the new Golang implementation and instructs the step to use the old Groovy one. Note that possibility to switch to the old Groovy implementation will be completely removed and this toggle will be deprecated after February 29th, 2024.
* @possibleValues true, false
*/
'useGoStep'
Expand Down Expand Up @@ -94,7 +94,7 @@ void call(Map parameters = [:]) {

def namedUser = jenkinsUtils.getJobStartedByUserId()

if (config.useGoStep == true) {
if (config.useGoStep != false) {
List credentials = [
[type: 'token', id: 'credentialsId', env: ['PIPER_tmsServiceKey']]
]
Expand All @@ -108,6 +108,9 @@ void call(Map parameters = [:]) {
return
}

echo "[TransportManagementService] Using deprecated Groovy implementation of '${STEP_NAME}' step instead of the default Golang one, since 'useGoStep' toggle parameter is explicitly set to 'false'."
echo "[TransportManagementService] WARNING: Note that the deprecated Groovy implementation will be completely removed after February 29th, 2024. Consider using the Golang implementation by not setting the 'useGoStep' toggle parameter to 'false'."

// telemetry reporting
new Utils().pushToSWA([
step : STEP_NAME,
Expand Down

0 comments on commit 80bf585

Please sign in to comment.