From 9b974af767bf5974086e3f34a63a717ae5bc4459 Mon Sep 17 00:00:00 2001 From: delarea Date: Thu, 14 Nov 2024 15:40:24 +0200 Subject: [PATCH] test --- src/main/java/io/jenkins/plugins/jfrog/JfStep.java | 8 +++++--- src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/jfrog/JfStep.java b/src/main/java/io/jenkins/plugins/jfrog/JfStep.java index 94ff042c..09df9ca1 100644 --- a/src/main/java/io/jenkins/plugins/jfrog/JfStep.java +++ b/src/main/java/io/jenkins/plugins/jfrog/JfStep.java @@ -49,7 +49,7 @@ @SuppressWarnings("unused") public class JfStep extends Builder implements SimpleBuildStep { private final ObjectMapper mapper = createMapper(); - private static final Version MIN_CLI_VERSION_PASSWORD_STDIN = new Version("2.31.3"); + static final Version MIN_CLI_VERSION_PASSWORD_STDIN = new Version("2.31.3"); static final String STEP_NAME = "jf"; protected String[] args; @@ -375,7 +375,7 @@ Version getJfrogCliVersion(Launcher.ProcStarter launcher) throws IOException, In * @param launcher The command launcher. * @return true if stdin-based password handling is supported; false otherwise. */ - private boolean isPasswordStdSupported(FilePath workspace, EnvVars env, Launcher launcher) throws IOException, InterruptedException { + public boolean isPasswordStdSupported(FilePath workspace, EnvVars env, Launcher launcher) throws IOException, InterruptedException { // Determine if the launcher is a plugin (custom) launcher boolean isPluginLauncher = launcher.getClass().getName().contains("org.jenkinsci.plugins"); if (isPluginLauncher) { @@ -383,7 +383,9 @@ private boolean isPasswordStdSupported(FilePath workspace, EnvVars env, Launcher } // Check CLI version Launcher.ProcStarter procStarter = launcher.launch().envs(env).pwd(workspace); - this.currentCliVersion = getJfrogCliVersion(procStarter); + if (this.currentCliVersion == null) { + this.currentCliVersion = getJfrogCliVersion(procStarter); + } return this.currentCliVersion.isAtLeast(MIN_CLI_VERSION_PASSWORD_STDIN); } } diff --git a/src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java b/src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java index 463d6320..58c2bcfb 100644 --- a/src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java +++ b/src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.stream.Stream; +import static io.jenkins.plugins.jfrog.JfStep.MIN_CLI_VERSION_PASSWORD_STDIN; import static io.jenkins.plugins.jfrog.JfStep.getJFrogCLIPath; import static io.jenkins.plugins.jfrog.JfrogInstallation.JFROG_BINARY_PATH; import static org.junit.jupiter.api.Assertions.*; @@ -90,7 +91,7 @@ void getJfrogCliVersionTest() throws IOException, InterruptedException { */ @ParameterizedTest @MethodSource("provideTestArguments") - void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, String expectedOutput) throws IOException { + void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, String expectedOutput) throws IOException, InterruptedException { // Mock the necessary objects JFrogPlatformInstance jfrogPlatformInstance = mock(JFrogPlatformInstance.class); CredentialsConfig credentialsConfig = mock(CredentialsConfig.class); @@ -103,9 +104,9 @@ void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, St // Create an instance of JfStep JfStep jfStep = new JfStep("Mock Test"); + // Mock CLI version jfStep.currentCliVersion = new Version(cliVersion); - jfStep.isPluginLauncher = isPluginLauncher; - + jfStep.usePasswordFromStdin = jfStep.currentCliVersion.isAtLeast(MIN_CLI_VERSION_PASSWORD_STDIN) && !isPluginLauncher; // Create an ArgumentListBuilder ArgumentListBuilder builder = new ArgumentListBuilder();