-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sap.piper | ||
|
||
import com.cloudbees.groovy.cps.NonCPS | ||
|
||
class CfManifestUtils { | ||
@NonCPS | ||
static Map transform(Map manifest) { | ||
if (manifest.applications[0].buildpacks) { | ||
manifest['applications'].each { Map application -> | ||
def buildpacks = application['buildpacks'] | ||
if (buildpacks) { | ||
if (buildpacks instanceof List) { | ||
if (buildpacks.size > 1) { | ||
throw new RuntimeException('More than one Cloud Foundry Buildpack is not supported. Please check your manifest.yaml file.') | ||
} | ||
application['buildpack'] = buildpacks[0] | ||
application.remove('buildpacks') | ||
} else { | ||
throw new RuntimeException('"buildpacks" in manifest.yaml is not a list. Please check your manifest.yaml file.') | ||
} | ||
} | ||
} | ||
} | ||
return manifest | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sap.piper | ||
|
||
import org.junit.Test | ||
|
||
import static org.junit.Assert.* | ||
|
||
class CfManifestUtilsTest { | ||
|
||
@Test | ||
void testManifestTransform() { | ||
Map testFixture = [applications: [[buildpacks: ['sap_java_buildpack']]]] | ||
Map expected = [applications: [[buildpack: 'sap_java_buildpack']]] | ||
def actual = CfManifestUtils.transform(testFixture) | ||
assertEquals(expected, actual) | ||
} | ||
|
||
@Test(expected = RuntimeException) | ||
void testManifestTransformMultipleBuildpacks() { | ||
Map testFixture = [applications: [[buildpacks: ['sap_java_buildpack', 'another_buildpack']]]] | ||
CfManifestUtils.transform(testFixture) | ||
} | ||
|
||
@Test | ||
void testManifestTransformShouldNotChange() { | ||
Map testFixture = [applications: [[buildpack: 'sap_java_buildpack']]] | ||
Map expected = [applications: [[buildpack: 'sap_java_buildpack']]] | ||
def actual = CfManifestUtils.transform(testFixture) | ||
assertEquals(expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters