-
Notifications
You must be signed in to change notification settings - Fork 56
Upgrade OpenshiftClient to 7.4.0 #632
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
4 commits
Select commit
Hold shift + click to select a range
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
129 changes: 0 additions & 129 deletions
129
builder/src/test/java/cz/xtf/builder/openshift/mocked/smoke/BasicOpenShiftTest.java
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
builder/src/test/java/cz/xtf/builder/openshift/smoke/BuildersTest.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,106 @@ | ||
| package cz.xtf.builder.openshift.smoke; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import cz.xtf.builder.builders.ConfigMapBuilder; | ||
| import cz.xtf.builder.builders.DeploymentConfigBuilder; | ||
| import io.fabric8.kubernetes.api.model.ConfigMap; | ||
| import io.fabric8.kubernetes.api.model.PodSpec; | ||
| import io.fabric8.openshift.api.model.DeploymentConfig; | ||
|
|
||
| /** | ||
| * Unit tests for XTF builder classes. | ||
| * Tests verify that builders correctly construct Kubernetes/OpenShift resource objects. | ||
| * | ||
| * Replaces BasicOpenShiftTest which used OpenShiftServer mock (removed in Fabric8 7.4.0). | ||
| */ | ||
| public class BuildersTest { | ||
|
|
||
| private static final String TEST_RESOURCE_LABEL_NAME_APP = "app"; | ||
| private static final String TEST_RESOURCE_LABEL_VALUE_APP = "xtf-core-test-openshift-mocked-smoke"; | ||
| private final static Map<String, String> TEST_RESOURCE_LABELS = Collections.singletonMap( | ||
| TEST_RESOURCE_LABEL_NAME_APP, TEST_RESOURCE_LABEL_VALUE_APP); | ||
|
|
||
| private static final String TEST_CONFIGMAP_NAME = "test-configmap"; | ||
| private static final String TEST_DEPLOYMENT_CONFIG_NAME = "test-deployment-config"; | ||
| private static final Integer TEST_DEPLOYMENT_CONFIG_REPLICAS = 3; | ||
|
|
||
| @Test | ||
| public void testConfigMapBuilder() { | ||
| // arrange | ||
| final String dataEntryKey = "test.properties"; | ||
| final String dataEntryValue = "foo=bar"; | ||
| final ConfigMap configMap = new ConfigMapBuilder(TEST_CONFIGMAP_NAME) | ||
| .addLabels(TEST_RESOURCE_LABELS) | ||
| .configEntry(dataEntryKey, dataEntryValue) | ||
| .build(); | ||
|
|
||
| // assert - verify the built ConfigMap structure | ||
| Assertions.assertNotNull(configMap, "ConfigMap resource creation failed."); | ||
| Assertions.assertEquals(TEST_CONFIGMAP_NAME, | ||
| configMap.getMetadata().getName(), | ||
| "ConfigMap resource has unexpected name."); | ||
| Assertions.assertEquals(1, | ||
| configMap.getData().entrySet().size(), | ||
| String.format("ConfigMap resource has unexpected data size: %d", | ||
| configMap.getData().entrySet().size())); | ||
|
|
||
| // safe now | ||
| final Map.Entry<String, String> dataEntry = configMap.getData().entrySet().stream().findFirst().get(); | ||
| Assertions.assertEquals(dataEntryKey, | ||
| dataEntry.getKey(), | ||
| String.format("ConfigMap resource has unexpected data entry key: %s", dataEntry.getKey())); | ||
| Assertions.assertEquals(dataEntryValue, | ||
| dataEntry.getValue(), | ||
| String.format("ConfigMap resource has unexpected data entry value: %s", dataEntry.getValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeploymentConfigBuilder() { | ||
| // arrange | ||
| final DeploymentConfig deploymentConfig = new DeploymentConfigBuilder(TEST_DEPLOYMENT_CONFIG_NAME) | ||
| .addLabels(TEST_RESOURCE_LABELS) | ||
| .setReplicas(TEST_DEPLOYMENT_CONFIG_REPLICAS) | ||
| .onImageChange() | ||
| .setRecreateStrategy() | ||
| .build(); | ||
|
|
||
| // assert - verify the built DeploymentConfig structure | ||
| Assertions.assertNotNull(deploymentConfig, "DeploymentConfig resource creation failed."); | ||
| Assertions.assertEquals(TEST_DEPLOYMENT_CONFIG_NAME, | ||
| deploymentConfig.getMetadata().getName(), | ||
| String.format("DeploymentConfig resource has unexpected name: %s.", | ||
| deploymentConfig.getMetadata().getName())); | ||
| Assertions.assertEquals(TEST_RESOURCE_LABELS, | ||
| deploymentConfig.getMetadata().getLabels(), | ||
| "DeploymentConfig resource has unexpected labels."); | ||
| Assertions.assertNotNull(deploymentConfig.getSpec(), | ||
| String.format("DeploymentConfig resource has null \".spec\"", deploymentConfig.getSpec())); | ||
| Assertions.assertEquals(TEST_DEPLOYMENT_CONFIG_REPLICAS, | ||
| deploymentConfig.getSpec().getReplicas(), | ||
| String.format("DeploymentConfig resource has unexpected \".spec.replicas\": %s.", | ||
| deploymentConfig.getSpec().getReplicas())); | ||
| Assertions.assertNotNull(deploymentConfig.getSpec().getStrategy(), | ||
| String.format("DeploymentConfig resource has null \".spec.strategy\"", | ||
| deploymentConfig.getSpec().getStrategy())); | ||
| Assertions.assertEquals("Recreate", | ||
| deploymentConfig.getSpec().getStrategy().getType(), | ||
| String.format("DeploymentConfig resource has unexpected \".spec.strategy\": %s.", | ||
| deploymentConfig.getSpec().getStrategy().getType())); | ||
| Assertions.assertNotNull(deploymentConfig.getSpec().getTemplate(), | ||
| String.format("DeploymentConfig resource has null \".spec.template\"", | ||
| deploymentConfig.getSpec().getTemplate())); | ||
| Assertions.assertNotNull(deploymentConfig.getSpec().getTemplate().getSpec(), | ||
| String.format("DeploymentConfig resource has null \".spec.template.spec\"", | ||
| deploymentConfig.getSpec().getTemplate().getSpec())); | ||
| PodSpec podSpec = deploymentConfig.getSpec().getTemplate().getSpec(); | ||
| Assertions.assertEquals(0, | ||
| podSpec.getContainers().size(), | ||
| String.format("DeploymentConfig resource has unexpected \".spec.template.spec.containers\": %s.", | ||
| podSpec.getContainers().size())); | ||
| } | ||
| } | ||
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
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.
suggestion (testing): Extend builder tests to assert labels (and potentially triggers) to better cover builder behavior
Currently these tests only assert name/data for
ConfigMapand a few fields forDeploymentConfig. Since labels are part of the builder contract (and you passTEST_RESOURCE_LABELS), please also assert that these labels are present inmetadata.labelsfor both resources. ForDeploymentConfigBuilder, also verify that the image change trigger configured viaonImageChange()appears in.spec.triggerswith the expected type, so these tests fully cover the intended builder behavior and can reliably replaceBasicOpenShiftTest.Suggested implementation:
To fully implement the requested coverage for the
DeploymentConfigBuilderas per your review comment, make the following changes in the same test class, inside thetestDeploymentConfigBuilder(or equivalent) method that builds and asserts theDeploymentConfig:Assert labels on the DeploymentConfig metadata
After the existing assertion that checks the DeploymentConfig name (and before or after the replicas assertion), add:
This assumes the variable holding the built resource is named
deploymentConfig. Adjust the variable name if different.Assert the presence of the ImageChange trigger
After the basic structural assertions (name, replicas, etc.), add assertions that verify the
ImageChangetrigger created by.onImageChange()is present in.spec.triggers:If your test currently doesn’t import
java.util.stream.*or similar, no extra imports are needed becausestream()is available onList. Ensure thedeploymentConfigtype isio.fabric8.openshift.api.model.DeploymentConfig(or compatible) sogetSpec().getTriggers()andgetType()on the trigger objects are available.These additions will ensure the tests cover both label propagation and trigger configuration behavior for the builders, so they can reliably replace the previous
BasicOpenShiftTestcoverage.