Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
java = "25"
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<!-- parent override -->
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>

<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>

<developers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.kubernetes.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import hudson.EnvVars;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.kubernetes.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.regex.Pattern;

Expand All @@ -16,8 +16,9 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Rule;
import org.junit.Test;
import org.jenkinsci.plugins.kubernetes.cli.helpers.JenkinsRuleExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.Result;
Expand All @@ -26,9 +27,9 @@
/**
* @author Max Laverse
*/
@ExtendWith(JenkinsRuleExtension.class)
public class KubectlBuildStepTest {
@Rule
public JenkinsRule r = new JenkinsRule();
public final JenkinsRule r = new JenkinsRule();

@Test
public void testListedCredentials() throws Exception {
Expand All @@ -55,7 +56,8 @@ public void testScopedCredentials() throws Exception {

WorkflowJob p = folder.createProject(WorkflowJob.class, "testScopedCredentials");
p.setDefinition(
new CpsFlowDefinition(TestResourceLoader.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
new CpsFlowDefinition(TestResourceLoader
.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
Expand All @@ -70,7 +72,8 @@ public void testMissingScopedCredentials() throws Exception {

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testMissingScopedCredentials");
p.setDefinition(
new CpsFlowDefinition(TestResourceLoader.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
new CpsFlowDefinition(TestResourceLoader
.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
Expand All @@ -85,7 +88,9 @@ public void testKubeConfigDisposedAlsoOnFailure() throws Exception {

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testCleanupOnFailure");
p.setDefinition(
new CpsFlowDefinition(TestResourceLoader.loadAsString("withKubeConfigPipelineFailing.groovy"), true));
new CpsFlowDefinition(
TestResourceLoader.loadAsString("withKubeConfigPipelineFailing.groovy"),
true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
Expand All @@ -97,7 +102,8 @@ public void testKubeConfigDisposedAlsoOnFailure() throws Exception {
public void testCredentialNotProvided() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testWithEmptyCredentials");
p.setDefinition(new CpsFlowDefinition(
TestResourceLoader.loadAsString("withKubeConfigPipelineMissingCredentials.groovy"), true));
TestResourceLoader.loadAsString("withKubeConfigPipelineMissingCredentials.groovy"),
true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
Expand All @@ -111,7 +117,8 @@ public void testUnsupportedCredential() throws Exception {

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testWithUnsupportedCredentials");
p.setDefinition(
new CpsFlowDefinition(TestResourceLoader.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
new CpsFlowDefinition(TestResourceLoader
.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
Expand All @@ -129,15 +136,17 @@ public void testEnvVariableFormat() throws Exception {

WorkflowJob p = folder.createProject(WorkflowJob.class, "testScopedCredentials");
p.setDefinition(
new CpsFlowDefinition(TestResourceLoader.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
new CpsFlowDefinition(TestResourceLoader
.loadAsString("withKubeConfigPipelineEchoPath.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();

assertNotNull(b);
assertBuildStatus(b, Result.SUCCESS);
String regExp = "Using temporary file '(.+).kube(.+)config'";
Pattern kubeConfigPathRegexp = Pattern.compile(regExp);
assertTrue("No line in the logs matched the regular expression '" + regExp + "': " + JenkinsRule.getLog(b),
kubeConfigPathRegexp.matcher(JenkinsRule.getLog(b)).find());
assertTrue(kubeConfigPathRegexp.matcher(JenkinsRule.getLog(b)).find(),
"No line in the logs matched the regular expression '" + regExp + "': "
+ JenkinsRule.getLog(b));
}

private void assertBuildStatus(WorkflowRun b, Result result) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jenkinsci.plugins.kubernetes.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsStore;
Expand All @@ -12,8 +12,9 @@
import org.jenkinsci.plugins.kubernetes.cli.helpers.DummyCredentials;
import org.jenkinsci.plugins.matrixauth.AuthorizationType;
import org.jenkinsci.plugins.matrixauth.PermissionEntry;
import org.junit.Rule;
import org.junit.Test;
import org.jenkinsci.plugins.kubernetes.cli.helpers.JenkinsRuleExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.FreeStyleBuild;
Expand All @@ -31,9 +32,9 @@
/**
* @author Max Laverse
*/
@ExtendWith(JenkinsRuleExtension.class)
public class KubectlBuildWrapperTest {
@Rule
public JenkinsRule r = new JenkinsRule();
public final JenkinsRule r = new JenkinsRule();

@Test
public void testEnvVariablePresent() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package org.jenkinsci.plugins.kubernetes.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsStore;
import com.cloudbees.plugins.credentials.domains.Domain;

import org.jenkinsci.plugins.kubernetes.cli.helpers.DummyCredentials;
import org.jenkinsci.plugins.kubernetes.cli.helpers.JenkinsRuleExtension;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.util.ListBoxModel;

/**
* @author Max Laverse
*/
@ExtendWith(JenkinsRuleExtension.class)
public class KubectlCredentialTest {
@Rule
public JenkinsRule r = new JenkinsRule();
public final JenkinsRule r = new JenkinsRule();

@Test
public void testListedCredentials() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -25,11 +25,12 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.jenkinsci.plugins.kubernetes.cli.helpers.JenkinsRuleExtension;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.Fingerprint;
Expand All @@ -39,22 +40,22 @@
/**
* @author Max Laverse
*/
@Category(KubectlIntegrationTest.class)
@Tag("org.jenkinsci.plugins.kubernetes.cli.KubectlIntegrationTest")
@ExtendWith(JenkinsRuleExtension.class)
public class KubectlIntegrationTest {
@Rule
public JenkinsRule r = new JenkinsRule();
public final JenkinsRule r = new JenkinsRule();

protected static final String CREDENTIAL_ID = "test-credentials";
protected static final String SECONDARY_CREDENTIAL_ID = "cred9999";

@Before
@BeforeEach
public void checkKubectlPresence() {
assertThat("The '" + kubectlBinaryName() + "' binary could not be found in the PATH", kubectlPresent());
}

@Test
public void testKubeConfigPermissionsRestrictedRead() throws Exception {
Assume.assumeFalse(System.getProperty("os.name").contains("Windows"));
Assumptions.assumeFalse(System.getProperty("os.name").contains("Windows"));

CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(),
DummyCredentials.usernamePasswordCredential(CREDENTIAL_ID));
Expand All @@ -75,7 +76,7 @@ public void testKubeConfigPermissionsRestrictedRead() throws Exception {

@Test
public void testKubeConfigPermissionsDefault() throws Exception {
Assume.assumeFalse(System.getProperty("os.name").contains("Windows"));
Assumptions.assumeFalse(System.getProperty("os.name").contains("Windows"));

CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(),
DummyCredentials.usernamePasswordCredential(CREDENTIAL_ID));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jenkinsci.plugins.kubernetes.cli;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -9,18 +9,19 @@
import com.cloudbees.plugins.credentials.domains.Domain;

import org.jenkinsci.plugins.kubernetes.cli.helpers.DummyCredentials;
import org.junit.Rule;
import org.junit.Test;
import org.jenkinsci.plugins.kubernetes.cli.helpers.JenkinsRuleExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.FreeStyleProject;

/**
* @author Max Laverse
*/
@ExtendWith(JenkinsRuleExtension.class)
public class MultiKubectlBuildWrapperTest {
@Rule
public JenkinsRule r = new JenkinsRule();
public final JenkinsRule r = new JenkinsRule();

@Test
public void testConfigurationPersistedOnSave() throws Exception {
Expand Down Expand Up @@ -56,7 +57,7 @@ public void testConfigurationPersistedOnSave() throws Exception {
" <credentialsId>test-credentials</credentialsId>\n" +
" </org.jenkinsci.plugins.kubernetes.cli.KubectlCredential>\n" +
" </kubectlCredentials>\n" +
" <restrictKubeConfigAccess>false</restrictKubeConfigAccess>\n" +
" <restrictKubeConfigAccess>false</restrictKubeConfigAccess>\n" +
" </org.jenkinsci.plugins.kubernetes.cli.MultiKubectlBuildWrapper>\n" +
" </buildWrappers>\n" +
"</project>", p.getConfigFile().asString());
Expand Down
Loading
Loading