From 71171c82ce27ee35723e6d99cb95ca158b343fca Mon Sep 17 00:00:00 2001 From: Puja Karakoti <144022134+pujakarakoti07@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:51:57 +0530 Subject: [PATCH] test: FileSecretIT tests work on Windows (3277) FileSecretIT Issue solved Signed-off-by: Puja --- test (gradle-plugin/it) : revert changes to FileDataSecretEnricher and add a separate test for windows + Revert changes to FileDataSecretEnricher + Add a separate test for windows that would provide expected files with windows line endings Signed-off-by: Rohan Kumar Co-authored-by: Rohan Kumar --- .../kubernetes_windows_line_endings.yml | 16 +++++ .../openshift_windows_line_endings.yml | 16 +++++ .../gradle/plugin/tests/FileSecretIT.java | 3 + .../plugin/tests/FileSecretWindowsIT.java | 58 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 gradle-plugin/it/src/it/secret-file/expected/kubernetes_windows_line_endings.yml create mode 100644 gradle-plugin/it/src/it/secret-file/expected/openshift_windows_line_endings.yml create mode 100644 gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretWindowsIT.java diff --git a/gradle-plugin/it/src/it/secret-file/expected/kubernetes_windows_line_endings.yml b/gradle-plugin/it/src/it/secret-file/expected/kubernetes_windows_line_endings.yml new file mode 100644 index 0000000000..bba7f7b9ec --- /dev/null +++ b/gradle-plugin/it/src/it/secret-file/expected/kubernetes_windows_line_endings.yml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: List +items: + - apiVersion: v1 + kind: Secret + metadata: + labels: + app: secret-file + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: secret-file + data: + # This contains application properties content with windows style line endings (CRLF) + application.properties: a2V5MSA9IHZhbHVlMQ0Ka2V5MiA9IHZhbHVlMg0Ka2V5MyA9IHZhbHVlMw== \ No newline at end of file diff --git a/gradle-plugin/it/src/it/secret-file/expected/openshift_windows_line_endings.yml b/gradle-plugin/it/src/it/secret-file/expected/openshift_windows_line_endings.yml new file mode 100644 index 0000000000..bba7f7b9ec --- /dev/null +++ b/gradle-plugin/it/src/it/secret-file/expected/openshift_windows_line_endings.yml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: List +items: + - apiVersion: v1 + kind: Secret + metadata: + labels: + app: secret-file + provider: jkube + version: "@ignore@" + group: org.eclipse.jkube.integration.tests.gradle + name: secret-file + data: + # This contains application properties content with windows style line endings (CRLF) + application.properties: a2V5MSA9IHZhbHVlMQ0Ka2V5MiA9IHZhbHVlMg0Ka2V5MyA9IHZhbHVlMw== \ No newline at end of file diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretIT.java index 16816ecab3..7c718a9b77 100644 --- a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretIT.java +++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretIT.java @@ -17,12 +17,15 @@ import org.eclipse.jkube.kit.common.ResourceVerify; import org.gradle.testkit.runner.BuildResult; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.RegisterExtension; import java.io.IOException; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +@DisabledOnOs(OS.WINDOWS) class FileSecretIT { @RegisterExtension private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension(); diff --git a/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretWindowsIT.java b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretWindowsIT.java new file mode 100644 index 0000000000..5fb9307572 --- /dev/null +++ b/gradle-plugin/it/src/test/java/org/eclipse/jkube/gradle/plugin/tests/FileSecretWindowsIT.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at: + * + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.jkube.gradle.plugin.tests; + +import net.minidev.json.parser.ParseException; +import org.eclipse.jkube.kit.common.ResourceVerify; +import org.gradle.testkit.runner.BuildResult; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.io.IOException; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@EnabledOnOs(OS.WINDOWS) +class FileSecretWindowsIT { + @RegisterExtension + private final ITGradleRunnerExtension gradleRunner = new ITGradleRunnerExtension(); + + @Test + void k8sResource_whenRunOnWindows_generatesK8sSecretWithWindowsLineEndings() throws IOException, ParseException { + // When + final BuildResult result = gradleRunner.withITProject("secret-file").withArguments("k8sResource").build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultKubernetesResourceFile(), + gradleRunner.resolveFile("expected", "kubernetes_windows_line_endings.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains("Using resource templates from") + .contains("Adding revision history limit to 2") + .contains("validating"); + } + + @Test + void ocResource_whenRunOnWindows_generatesK8sSecretWithWindowsLineEndings() throws IOException, ParseException { + // When + final BuildResult result = gradleRunner.withITProject("secret-file").withArguments("ocResource").build(); + // Then + ResourceVerify.verifyResourceDescriptors(gradleRunner.resolveDefaultOpenShiftResourceFile(), + gradleRunner.resolveFile("expected", "openshift_windows_line_endings.yml")); + assertThat(result).extracting(BuildResult::getOutput).asString() + .contains("Using resource templates from") + .contains("Adding revision history limit to 2") + .contains("validating"); + } +}