Skip to content

Commit

Permalink
test: assertion verifies GenericKubernetesResource fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Nov 2, 2021
1 parent 6c214f5 commit 919d0ea
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.fabric8.openshift.client.server.mock;

import io.fabric8.kubernetes.api.model.APIGroupListBuilder;
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
Expand Down Expand Up @@ -45,6 +46,7 @@
import java.util.Map;

import static java.util.Collections.singletonMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -184,13 +186,22 @@ void shouldLoadTemplateWithNumberParameters() {
map.put("PORT", "8080");
KubernetesList list = client.templates().withParameters(map).load(getClass().getResourceAsStream("/template-with-number-params.yml")).processLocally(map);
assertListIsServiceWithPort8080(list);
assertThat(list.getItems()).singleElement()
.isInstanceOf(Service.class)
.extracting("spec.ports").asList().singleElement()
.hasFieldOrPropertyWithValue("port", 8080);
}

@Test
void shouldGetTemplateWithNumberParameters() {
OpenShiftClient client = new DefaultOpenShiftClient(new OpenShiftConfigBuilder().withDisableApiGroupCheck(true).build());
Template template = client.templates().load(getClass().getResourceAsStream("/template-with-number-params.yml")).get();
assertTrue(Serialization.asYaml(template.getObjects().get(0)).contains("{PORT}"));
assertThat(template)
.extracting(Template::getObjects).asList()
.singleElement()
.isInstanceOf(GenericKubernetesResource.class)
.extracting("additionalProperties.spec.ports").asList().singleElement()
.hasFieldOrPropertyWithValue("port", "${PORT}");
}

protected void assertListIsServiceWithPort8080(KubernetesList list) {
Expand Down

0 comments on commit 919d0ea

Please sign in to comment.