-
Notifications
You must be signed in to change notification settings - Fork 42
Add support for cnb (#1629) - LMCROSSITXSADEPLOY-2993 #1630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
624560f
Add support for cnb (#1629)
s-yonkov-yonkov 629713f
Apply formatting
s-yonkov-yonkov f89fffb
Add lifecycle to supported parameters
s-yonkov-yonkov 20d0dff
Changes on comments
s-yonkov-yonkov c978648
Adopt released cf-java-client
s-yonkov-yonkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
149 changes: 149 additions & 0 deletions
149
...t/java/org/cloudfoundry/multiapps/controller/core/parser/StagingParametersParserTest.java
This file contains hidden or 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,149 @@ | ||
| package org.cloudfoundry.multiapps.controller.core.parser; | ||
|
|
||
| import java.text.MessageFormat; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.sap.cloudfoundry.client.facade.domain.LifecycleType; | ||
| import com.sap.cloudfoundry.client.facade.domain.Staging; | ||
| import org.cloudfoundry.multiapps.common.ContentException; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.util.CollectionUtils; | ||
|
|
||
| import static org.cloudfoundry.multiapps.controller.core.Messages.BUILDPACKS_NOT_ALLOWED_WITH_DOCKER; | ||
| import static org.cloudfoundry.multiapps.controller.core.Messages.BUILDPACKS_REQUIRED_FOR_CNB; | ||
| import static org.cloudfoundry.multiapps.controller.core.Messages.DOCKER_INFO_NOT_ALLOWED_WITH_LIFECYCLE; | ||
| import static org.cloudfoundry.multiapps.controller.core.Messages.DOCKER_INFO_REQUIRED; | ||
| import static org.cloudfoundry.multiapps.controller.core.Messages.UNSUPPORTED_LIFECYCLE_VALUE; | ||
| import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.BUILDPACK; | ||
| import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.BUILDPACKS; | ||
| import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.DOCKER; | ||
| import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.LIFECYCLE; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class StagingParametersParserTest { | ||
|
|
||
| public static final String INVALID_VALUE = "invalid_value"; | ||
| public static final String CNB = "cnb"; | ||
| public static final String CUSTOM_BUILDPACK_URL = "custom-buildpack-url"; | ||
| public static final String IMAGE = "image"; | ||
| public static final String CLOUDFOUNDRY_TEST_APP = "cloudfoundry/test-app"; | ||
| public static final String SOME_BUILDPACK = "some-buildpack"; | ||
| private StagingParametersParser parser; | ||
| private List<Map<String, Object>> parametersList; | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| parser = new StagingParametersParser(); | ||
| parametersList = new ArrayList<>(); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithCnbAndValidBuildpacks() { | ||
| parametersList.add(mapOf(LIFECYCLE, CNB)); | ||
| parametersList.add(mapOf(BUILDPACKS, List.of(CUSTOM_BUILDPACK_URL))); | ||
|
|
||
| Staging staging = parser.parse(parametersList); | ||
|
|
||
| assertNotNull(staging); | ||
| assertEquals(LifecycleType.CNB, staging.getLifecycleType()); | ||
| assertNotNull(staging.getBuildpacks()); | ||
| assertEquals(1, staging.getBuildpacks() | ||
| .size()); | ||
| assertEquals(CUSTOM_BUILDPACK_URL, staging.getBuildpacks() | ||
| .get(0)); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithCnbAndNoBuildpacks() { | ||
| parametersList.add(mapOf(LIFECYCLE, CNB)); | ||
|
|
||
| ContentException exception = assertThrows(ContentException.class, () -> parser.parse(parametersList)); | ||
| assertEquals(BUILDPACKS_REQUIRED_FOR_CNB, exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithDockerAndValidDockerInfo() { | ||
| parametersList.add(getDockerParams()); | ||
|
|
||
| Staging staging = parser.parse(parametersList); | ||
|
|
||
| assertNotNull(staging); | ||
| assertEquals(LifecycleType.DOCKER, staging.getLifecycleType()); | ||
| assertNotNull(staging.getDockerInfo()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithDockerAndBuildpacksProvided() { | ||
| parametersList.add(getDockerParams()); | ||
| parametersList.add(mapOf(BUILDPACKS, List.of(SOME_BUILDPACK))); | ||
|
|
||
| ContentException exception = assertThrows(ContentException.class, () -> parser.parse(parametersList)); | ||
| assertEquals(BUILDPACKS_NOT_ALLOWED_WITH_DOCKER, exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithBuildpackAndNoBuildpacks() { | ||
| parametersList.add(mapOf(LIFECYCLE, BUILDPACK)); | ||
|
|
||
| Staging staging = parser.parse(parametersList); | ||
|
|
||
| assertNotNull(staging); | ||
| assertEquals(LifecycleType.BUILDPACK, staging.getLifecycleType()); | ||
|
|
||
| List<String> buildpacks = staging.getBuildpacks(); | ||
| assertTrue(CollectionUtils.isEmpty(buildpacks)); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithInvalidLifecycleValue() { | ||
| parametersList.add(mapOf(LIFECYCLE, INVALID_VALUE)); | ||
|
|
||
| ContentException exception = assertThrows(ContentException.class, () -> parser.parse(parametersList)); | ||
| assertEquals(MessageFormat.format(UNSUPPORTED_LIFECYCLE_VALUE, INVALID_VALUE), exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateLifecycleWithDockerAndNoDockerInfo() { | ||
| parametersList.add(mapOf(LIFECYCLE, DOCKER)); | ||
|
|
||
| ContentException exception = assertThrows(ContentException.class, () -> parser.parse(parametersList)); | ||
| assertEquals(DOCKER_INFO_REQUIRED, exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateDockerInfoWithNonDockerLifecycle() { | ||
| parametersList.add(mapOf(LIFECYCLE, CNB)); | ||
| parametersList.add(mapOf(BUILDPACKS, List.of(SOME_BUILDPACK))); | ||
| parametersList.add(getDockerParams()); | ||
|
|
||
| ContentException exception = assertThrows(ContentException.class, () -> parser.parse(parametersList)); | ||
| assertEquals(MessageFormat.format(DOCKER_INFO_NOT_ALLOWED_WITH_LIFECYCLE, LifecycleType.CNB), exception.getMessage()); | ||
| } | ||
|
|
||
| @Test | ||
| void testValidateWithAllParametersMissing() { | ||
| Staging staging = parser.parse(parametersList); | ||
|
|
||
| assertNotNull(staging); | ||
| assertNull(staging.getLifecycleType()); | ||
| assertTrue(CollectionUtils.isEmpty(staging.getBuildpacks())); | ||
| assertNull(staging.getDockerInfo()); | ||
| } | ||
|
|
||
| private static Map<String, Object> mapOf(String key, Object value) { | ||
| return Collections.singletonMap(key, value); | ||
| } | ||
|
|
||
| private static Map<String, Object> getDockerParams() { | ||
| return Map.of(LIFECYCLE, DOCKER, DOCKER, Map.of(IMAGE, CLOUDFOUNDRY_TEST_APP)); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the method LifecycleType::from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed