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"));
}
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);
}
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"));
}
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")));
}
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));
}
Aggregations