Search in sources :

Example 6 with TestCaseName

use of junitparams.naming.TestCaseName in project kubernetes-plugin by jenkinsci.

the class PodTemplateBuilderTest method testValidateDockerRegistryPrefixOverrideWithSlashSuffix.

@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testValidateDockerRegistryPrefixOverrideWithSlashSuffix(boolean directConnection) throws Exception {
    cloud.setDirectConnection(directConnection);
    DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX = "jenkins.docker.com/docker-hub/";
    PodTemplate template = new PodTemplate();
    template.setYaml(loadYamlFile("pod-busybox.yaml"));
    setupStubs();
    Pod pod = new PodTemplateBuilder(template, slave).build();
    // check containers
    Map<String, Container> containers = toContainerMap(pod);
    assertEquals(2, containers.size());
    assertEquals("busybox", containers.get("busybox").getImage());
    assertEquals(DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX + DEFAULT_JNLP_IMAGE, containers.get("jnlp").getImage());
    assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 7 with TestCaseName

use of junitparams.naming.TestCaseName in project kubernetes-plugin by jenkinsci.

the class PodTemplateBuilderTest method testInheritsFromWithYaml.

/**
 * This is counter intuitive, the yaml contents are ignored because the parent fields are merged first with the
 * child ones. Then the fields override what is defined in the yaml, so in effect the parent resource limits and
 * requests are used.
 */
@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testInheritsFromWithYaml(boolean directConnection) throws Exception {
    cloud.setDirectConnection(directConnection);
    PodTemplate parent = new PodTemplate();
    ContainerTemplate container1 = new ContainerTemplate("jnlp", "image1");
    container1.setResourceLimitCpu("1");
    container1.setResourceLimitMemory("1Gi");
    container1.setResourceRequestCpu("100m");
    container1.setResourceRequestMemory("156Mi");
    container1.setRunAsUser("1000");
    container1.setRunAsGroup("2000");
    parent.setContainers(Arrays.asList(container1));
    PodTemplate template = new PodTemplate();
    template.setYaml(loadYamlFile("pod-overrides.yaml"));
    template.setInheritFrom("parent");
    setupStubs();
    PodTemplate result = combine(parent, template);
    Pod pod = new PodTemplateBuilder(result, slave).build();
    Map<String, Container> containers = toContainerMap(pod);
    assertEquals(1, containers.size());
    Container jnlp = containers.get("jnlp");
    PodTemplateUtilsTest.assertQuantity("1", jnlp.getResources().getLimits().get("cpu"));
    PodTemplateUtilsTest.assertQuantity("1Gi", jnlp.getResources().getLimits().get("memory"));
    PodTemplateUtilsTest.assertQuantity("100m", jnlp.getResources().getRequests().get("cpu"));
    PodTemplateUtilsTest.assertQuantity("156Mi", jnlp.getResources().getRequests().get("memory"));
    assertEquals(Long.valueOf(1000L), jnlp.getSecurityContext().getRunAsUser());
    assertEquals(Long.valueOf(2000L), jnlp.getSecurityContext().getRunAsGroup());
    validateContainers(pod, slave, directConnection);
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 8 with TestCaseName

use of junitparams.naming.TestCaseName in project kubernetes-plugin by jenkinsci.

the class PodTemplateBuilderTest method testValidateDockerRegistryPrefixOverride.

@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testValidateDockerRegistryPrefixOverride(boolean directConnection) throws Exception {
    cloud.setDirectConnection(directConnection);
    DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX = "jenkins.docker.com/docker-hub";
    PodTemplate template = new PodTemplate();
    template.setYaml(loadYamlFile("pod-busybox.yaml"));
    setupStubs();
    Pod pod = new PodTemplateBuilder(template, slave).build();
    // check containers
    Map<String, Container> containers = toContainerMap(pod);
    assertEquals(2, containers.size());
    assertEquals("busybox", containers.get("busybox").getImage());
    assertEquals(DEFAULT_JNLP_DOCKER_REGISTRY_PREFIX + "/" + DEFAULT_JNLP_IMAGE, containers.get("jnlp").getImage());
    assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 9 with TestCaseName

use of junitparams.naming.TestCaseName in project kubernetes-plugin by jenkinsci.

the class PodTemplateBuilderTest method testBuildFromYaml.

@Test
@TestCaseName("{method}(directConnection={0})")
@Parameters({ "true", "false" })
public void testBuildFromYaml(boolean directConnection) throws Exception {
    cloud.setDirectConnection(directConnection);
    PodTemplate template = new PodTemplate();
    template.setYaml(loadYamlFile("pod-busybox.yaml"));
    setupStubs();
    Pod pod = new PodTemplateBuilder(template, slave).build();
    validatePod(pod, directConnection);
    assertThat(pod.getMetadata().getLabels(), hasEntry("jenkins", "slave"));
    Map<String, Container> containers = toContainerMap(pod);
    assertEquals(2, containers.size());
    Container container0 = containers.get("busybox");
    assertNotNull(container0.getResources());
    assertNotNull(container0.getResources().getRequests());
    assertNotNull(container0.getResources().getLimits());
    assertThat(container0.getResources().getRequests(), hasEntry("example.com/dongle", new Quantity("42")));
    assertThat(container0.getResources().getLimits(), hasEntry("example.com/dongle", new Quantity("42")));
}
Also used : PodTemplateBuilder(org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Quantity(io.fabric8.kubernetes.api.model.Quantity) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 10 with TestCaseName

use of junitparams.naming.TestCaseName in project mod-inventory-storage by folio-org.

the class ItemEffectiveCallNumberComponentsTest method canCalculateEffectiveCallNumberPropertyOnUpdate.

@Test
@Parameters(source = ItemEffectiveCallNumberComponentsTestData.class, method = "updatePropertiesParams")
@TestCaseName("[{index}]: {params}")
public void canCalculateEffectiveCallNumberPropertyOnUpdate(CallNumberComponentPropertyNames callNumberProperties, String holdingsInitValue, String holdingsTargetValue, String itemInitValue, String itemTargetValue) {
    final String holdingsPropertyName = callNumberProperties.holdingsPropertyName;
    final String itemPropertyName = callNumberProperties.itemPropertyName;
    final String effectivePropertyName = callNumberProperties.effectivePropertyName;
    final String initEffectiveValue = StringUtils.firstNonBlank(itemInitValue, holdingsInitValue);
    final String targetEffectiveValue = StringUtils.firstNonBlank(itemTargetValue, holdingsTargetValue);
    IndividualResource holdings = createHoldingsWithPropertySetAndInstance(holdingsPropertyName, holdingsInitValue);
    IndividualResource createdItem = itemsClient.create(nodWithNoBarcode(holdings.getId()).put(itemPropertyName, itemInitValue));
    JsonObject effectiveCallNumberComponents = createdItem.getJson().getJsonObject("effectiveCallNumberComponents");
    assertNotNull(effectiveCallNumberComponents);
    assertThat(effectiveCallNumberComponents.getString(effectivePropertyName), is(initEffectiveValue));
    holdingsClient.replace(holdings.getId(), getHoldingsById(holdings.getJson()).put(holdingsPropertyName, holdingsTargetValue));
    var itemAfterHoldingsUpdate = getById(createdItem.getJson());
    assertUpdateEventForItem(createdItem.getJson(), itemAfterHoldingsUpdate);
    if (!Objects.equals(itemInitValue, itemTargetValue)) {
        itemsClient.replace(createdItem.getId(), itemAfterHoldingsUpdate.copy().put(itemPropertyName, itemTargetValue));
        await().untilAsserted(() -> {
            var instanceId = holdings.getJson().getString("instanceId");
            var itemId = createdItem.getId().toString();
            var lastItemEvent = getLastItemEvent(instanceId, itemId);
            assertTrue(lastItemEvent.value().getJsonObject("new").getInteger("_version") > 1);
            assertUpdateEventForItem(itemAfterHoldingsUpdate, itemsClient.getById(createdItem.getId()).getJson());
        });
    }
    final JsonObject updatedItem = itemsClient.getById(createdItem.getId()).getJson();
    final JsonObject updatedEffectiveCallNumberComponents = updatedItem.getJsonObject("effectiveCallNumberComponents");
    assertNotNull(updatedEffectiveCallNumberComponents);
    assertThat(updatedEffectiveCallNumberComponents.getString(effectivePropertyName), is(targetEffectiveValue));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Aggregations

Parameters (junitparams.Parameters)16 TestCaseName (junitparams.naming.TestCaseName)16 Test (org.junit.Test)16 Container (io.fabric8.kubernetes.api.model.Container)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 PodTemplateBuilder (org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder)7 FieldScope (com.github.victools.jsonschema.generator.FieldScope)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AbstractTypeAwareTest (com.github.victools.jsonschema.generator.AbstractTypeAwareTest)2 ConfigFunction (com.github.victools.jsonschema.generator.ConfigFunction)2 JsonObject (io.vertx.core.json.JsonObject)2 IndividualResource (org.folio.rest.support.IndividualResource)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MethodScope (com.github.victools.jsonschema.generator.MethodScope)1 SchemaCleanUpUtils (com.github.victools.jsonschema.generator.impl.SchemaCleanUpUtils)1 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 KeyValueEnvVar (org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar)1