Skip to content

Commit

Permalink
test(openapi): isNamespaced for resources with no metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored Sep 18, 2024
1 parent 5a7e031 commit cce22ee
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashSet;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -94,11 +95,25 @@ void hasMetadata() {
assertTrue(templateContext.isHasMetadata());
}

@Test
void hasMetadata_podSpec() {
final Schema<?> schema = (Schema<?>) settings.getOpenAPI().getComponents().getSchemas().get("io.k8s.api.core.v1.PodSpec");
templateContext = new TemplateContext(settings, new AbstractMap.SimpleEntry<>("io.k8s.api.core.v1.PodSpec", schema));
assertFalse(templateContext.isHasMetadata());
}

@Test
void kubernetesListType() {
assertNull(templateContext.getKubernetesListType());
}

@Test
void kubernetesListType_podList() {
final Schema<?> schema = (Schema<?>) settings.getOpenAPI().getComponents().getSchemas().get("io.k8s.api.core.v1.PodList");
templateContext = new TemplateContext(settings, new AbstractMap.SimpleEntry<>("io.k8s.api.core.v1.PodList", schema));
assertEquals("Pod", templateContext.getKubernetesListType());
}

@Test
void context() {
assertEquals(1, templateContext.getContext().size());
Expand All @@ -123,4 +138,22 @@ void addAllImports() {
assertEquals(new HashSet<>(Arrays.asList("java.util.List", "java.util.Map")), templateContext.getContext().get("imports"));
}

@Test
void isNamespaced() {
assertTrue(templateContext.isNamespaced());
}

@Test
void isNamespaced_node() {
final Schema<?> schema = (Schema<?>) settings.getOpenAPI().getComponents().getSchemas().get("io.k8s.api.core.v1.Node");
templateContext = new TemplateContext(settings, new AbstractMap.SimpleEntry<>("io.k8s.api.core.v1.Node", schema));
assertFalse(templateContext.isNamespaced());
}

@Test
void isNamespaced_podSpec() {
final Schema<?> schema = (Schema<?>) settings.getOpenAPI().getComponents().getSchemas().get("io.k8s.api.core.v1.PodSpec");
templateContext = new TemplateContext(settings, new AbstractMap.SimpleEntry<>("io.k8s.api.core.v1.PodSpec", schema));
assertFalse(templateContext.isNamespaced());
}
}

0 comments on commit cce22ee

Please sign in to comment.