venkateshwaracholan commented on code in PR #4807: URL: https://github.com/apache/polaris/pull/4807#discussion_r3433968033
########## tools/container-spec-helper/src/test/java/org/apache/polaris/containerspec/ContainerSpecHelperTest.java: ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.polaris.containerspec; + +import static org.apache.polaris.containerspec.ContainerSpecHelper.containerSpecHelper; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.testcontainers.utility.DockerImageName; + +class ContainerSpecHelperTest { + + private static final String CONTAINER_NAME = "test"; + private static final String DEFAULT_IMAGE = "docker.io/test/image:1.2.3"; + private static final String EXPECTED_PARTIAL_CONFIG_MESSAGE = + "Must specify both image name and tag via system properties or environment variables, or omit both to use the default " + + DEFAULT_IMAGE + + " from Dockerfile-test-version"; + + @AfterEach + void clearContainerImageOverrides() { + System.clearProperty("it.polaris.container." + CONTAINER_NAME + ".image"); + System.clearProperty("it.polaris.container." + CONTAINER_NAME + ".tag"); + System.clearProperty("polaris.testing." + CONTAINER_NAME + ".image"); + System.clearProperty("polaris.testing." + CONTAINER_NAME + ".tag"); + } + + @Test + void dockerImageNameUsesDefaultFromDockerfileWhenNoOverrides() { + DockerImageName imageName = + containerSpecHelper(CONTAINER_NAME, ContainerSpecHelperTest.class).dockerImageName(null); + + assertThat(imageName).isEqualTo(DockerImageName.parse(DEFAULT_IMAGE)); + } + + @Test + void dockerImageNameUsesExplicitImageNameWhenProvided() { + DockerImageName imageName = + containerSpecHelper(CONTAINER_NAME, ContainerSpecHelperTest.class) + .dockerImageName("docker.io/explicit:4.5.6"); + + assertThat(imageName).isEqualTo(DockerImageName.parse("docker.io/explicit:4.5.6")); + } + + @Test + void dockerImageNameUsesBothSystemPropertiesWhenProvided() { + System.setProperty("polaris.testing." + CONTAINER_NAME + ".image", "docker.io/custom/image"); + System.setProperty("polaris.testing." + CONTAINER_NAME + ".tag", "9.9.9"); Review Comment: @dimas-b Thanks for the suggestion. I updated the tests to inject property and environment lookups instead of modifying JVM system properties directly. The production path is unchanged, and the new approach also allowed adding coverage for environment variable handling and precedence rules. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
