Skip to content

Commit

Permalink
fix(test): configured failing tests for Windows
Browse files Browse the repository at this point in the history
Signed-off-by: l3002 <tanmaymathpal4545@gmail.com>
  • Loading branch information
l3002 committed Feb 27, 2024
1 parent c850332 commit 56b4dad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.commons.io.FilenameUtils.separatorsToSystem;
import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.eclipse.jkube.kit.common.util.JKubeProjectUtil.getProperty;
import static org.eclipse.jkube.kit.common.util.YamlUtil.listYamls;
Expand Down Expand Up @@ -105,9 +106,9 @@ public static HelmConfig.HelmConfigBuilder initHelmConfig(
helmConfig.setTypes(resolveHelmTypes(defaultHelmType, project));

helmConfig.setSourceDir(resolveFromPropertyOrDefault(PROPERTY_SOURCE_DIR, project, helmConfig::getSourceDir,
() -> String.format("%s/META-INF/jkube/", project.getOutputDirectory())));
() -> separatorsToSystem(String.format("%s/META-INF/jkube/", project.getOutputDirectory()))));
helmConfig.setOutputDir(resolveFromPropertyOrDefault(PROPERTY_OUTPUT_DIR, project, helmConfig::getOutputDir,
() -> String.format("%s/jkube/helm/%s", project.getBuildDirectory(), helmConfig.getChart())));
() -> separatorsToSystem(String.format("%s/jkube/helm/%s", project.getBuildDirectory(), helmConfig.getChart()))));
helmConfig.setIcon(resolveFromPropertyOrDefault(PROPERTY_ICON, project, helmConfig::getIcon,
() -> findIconURL(new File(helmConfig.getSourceDir()), helmConfig.getTypes())));
helmConfig.setAppVersion(resolveFromPropertyOrDefault(PROPERTY_APP_VERSION, project, helmConfig::getAppVersion, project::getVersion));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand Down Expand Up @@ -434,6 +437,7 @@ void setUp() {

@Test
@DisplayName("Sends chart metadata file, tarball and manifest file in separate requests")
@DisabledOnOs(OS.WINDOWS)
void withSuccessfulUpload_shouldUploadBlobsAndUpdateManifest() throws Exception {
// Given
helmConfig.setChartExtension("tar.gz");
Expand Down Expand Up @@ -481,6 +485,54 @@ void withSuccessfulUpload_shouldUploadBlobsAndUpdateManifest() throws Exception
" } ]\n" +
"}");
}
@Test
@DisplayName("On Windows, Sends chart metadata file, tarball and manifest file in separate requests")
@EnabledOnOs(OS.WINDOWS)
void withSuccessfulUploadOnWindows_shouldUploadBlobsAndUpdateManifest() throws Exception {
helmConfig.setChartExtension("tar.gz");
Files.write(
Paths.get(helmConfig.getOutputDir()).resolve("kubernetes")
.resolve("Helm-Chart-1337-SNAPSHOT.tar.gz"),
"I'm a tar.gz, not a .tgz".getBytes(StandardCharsets.UTF_8));
Files.write(Paths.get(helmConfig.getOutputDir()).resolve("kubernetes").resolve("Chart.yaml"),
"---\r\napiVersion: v1\r\nname: test-chart\r\nversion: 0.0.1".getBytes(StandardCharsets.UTF_8));

mockServer.expect().post()
.withPath("/v2/test-chart/blobs/uploads/")
.andReply(new TestMockResponseProvider(202, singletonMap("Location", "/v2/test-chart/blobs/upload/first-upload-endpoint"), null))
.once();
mockServer.expect().post()
.withPath("/v2/test-chart/blobs/uploads/")
.andReply(new TestMockResponseProvider(202, singletonMap("Location", "/v2/test-chart/blobs/upload/second-upload-endpoint"), null))
.once();
mockServer.expect().put()
.withPath("/v2/test-chart/blobs/upload/first-upload-endpoint?digest=sha256%3A46a607aed71245e2489a79ad8b401b269565de36f3aa7eadf6f7e368a8938a43")
.andReply(new TestMockResponseProvider(200, singletonMap("Docker-Content-Digest", "sha256:46a607aed71245e2489a79ad8b401b269565de36f3aa7eadf6f7e368a8938a43"), null))
.once();
mockServer.expect().put()
.withPath("/v2/test-chart/blobs/upload/second-upload-endpoint?digest=sha256%3Ac7051faa2fb28d147b34070a6bce25eaf1ee6bb4ca3b47af5ee6148d50079154")
.andReply(new TestMockResponseProvider(200, singletonMap("Docker-Content-Digest", "sha256:c7051faa2fb28d147b34070a6bce25eaf1ee6bb4ca3b47af5ee6148d50079154"), null))
.once();
mockServer.expect().put()
.withPath("/v2/test-chart/manifests/0.0.1")
.andReply(new TestMockResponseProvider(200, singletonMap("Docker-Content-Digest", "manifestdigest"), null))
.once();
helmService.uploadHelmChart(helmConfig);
assertThat(mockServer.getLastRequest().getBody().readUtf8())
.isEqualTo("{\r\n" +
" \"schemaVersion\" : 2,\r\n" +
" \"config\" : {\r\n" +
" \"mediaType\" : \"application/vnd.cncf.helm.config.v1+json\",\r\n" +
" \"digest\" : \"sha256:46a607aed71245e2489a79ad8b401b269565de36f3aa7eadf6f7e368a8938a43\",\r\n" +
" \"size\" : 77\r\n" +
" },\r\n" +
" \"layers\" : [ {\r\n" +
" \"mediaType\" : \"application/vnd.cncf.helm.chart.content.v1.tar+gzip\",\r\n" +
" \"digest\" : \"sha256:c7051faa2fb28d147b34070a6bce25eaf1ee6bb4ca3b47af5ee6148d50079154\",\r\n" +
" \"size\" : 24\r\n" +
" } ]\r\n" +
"}");
}
}

private void expect(HttpMethod method, String path, ServerResponse response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import static org.apache.commons.io.FilenameUtils.separatorsToSystem;
import static org.assertj.core.api.Assertions.assertThat;

class HelmServiceUtilTest {
Expand Down Expand Up @@ -89,9 +90,9 @@ void initHelmConfig_withNoConfig_shouldInitConfigWithDefaultValues() throws IOEx
.hasFieldOrProperty("icon")
.hasFieldOrPropertyWithValue("lintStrict", false)
.hasFieldOrPropertyWithValue("lintQuiet", false);
assertThat(result.getSourceDir()).endsWith("target/classes/META-INF/jkube/");
assertThat(result.getOutputDir()).endsWith("target/jkube/helm/artifact-id");
assertThat(result.getTarballOutputDir()).endsWith("target/jkube/helm/artifact-id");
assertThat(result.getSourceDir()).endsWith(separatorsToSystem("target/classes/META-INF/jkube/"));
assertThat(result.getOutputDir()).endsWith(separatorsToSystem("target/jkube/helm/artifact-id"));
assertThat(result.getTarballOutputDir()).endsWith(separatorsToSystem("target/jkube/helm/artifact-id"));
}

@Test
Expand Down

0 comments on commit 56b4dad

Please sign in to comment.