Search in sources :

Example 1 with SnippetizerTester

use of org.jenkinsci.plugins.workflow.cps.SnippetizerTester in project kubernetes-plugin by jenkinsci.

the class PodTemplateStepTest method configRoundTrip.

@Issue("JENKINS-57828")
@Test
public void configRoundTrip() throws Exception {
    SnippetizerTester st = new SnippetizerTester(rule);
    PodTemplateStep step = new PodTemplateStep();
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setName("podTest");
    st.assertRoundTrip(step, "podTemplate(name: 'podTest') {\n    // some block\n}");
    step.setName("");
    step.setInstanceCap(5);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 5) {\n    // some block\n}");
    step.setInstanceCap(0);
    step.setInstanceCap(6);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 6) {\n    // some block\n}");
    // make sure this resets instanceCap
    step.setInstanceCap(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setInstanceCap(7);
    st.assertRoundTrip(step, "podTemplate(instanceCap: 7) {\n    // some block\n}");
    // make sure this resets instanceCap
    step.setInstanceCap(Integer.MAX_VALUE);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setLabel("podLabel");
    st.assertRoundTrip(step, "podTemplate(label: 'podLabel') {\n    // some block\n}");
    step.setLabel("");
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    // this is the default, it should not appear in the snippet.
    step.setPodRetention(PodRetention.getPodTemplateDefault());
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setPodRetention(new OnFailure());
    st.assertRoundTrip(step, "podTemplate(podRetention: onFailure()) {\n    // some block\n}");
    step.setPodRetention(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setWorkspaceVolume(new DynamicPVCWorkspaceVolume());
    st.assertRoundTrip(step, "podTemplate(workspaceVolume: dynamicPVC()) {\n    // some block\n}");
    // this is the default, it should not be in the snippet.
    step.setWorkspaceVolume(new EmptyDirWorkspaceVolume(false));
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    DynamicPVCWorkspaceVolume workspaceVolume = new DynamicPVCWorkspaceVolume();
    workspaceVolume.setAccessModes("ReadWriteMany");
    step.setWorkspaceVolume(workspaceVolume);
    st.assertRoundTrip(step, "podTemplate(workspaceVolume: dynamicPVC(accessModes: 'ReadWriteMany')) {\n    // some block\n}");
    step.setWorkspaceVolume(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setActiveDeadlineSeconds(60);
    st.assertRoundTrip(step, "podTemplate(activeDeadlineSeconds: 60) {\n    // some block\n}");
    step.setActiveDeadlineSeconds(0);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
    step.setInheritFrom("fooBar");
    st.assertRoundTrip(step, "podTemplate(inheritFrom: 'fooBar') {\n    // some block\n}");
    step.setInheritFrom("");
    st.assertRoundTrip(step, "podTemplate(inheritFrom: '') {\n    // some block\n}");
    step.setInheritFrom(null);
    st.assertRoundTrip(step, "podTemplate {\n    // some block\n}");
}
Also used : DynamicPVCWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume) SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) EmptyDirWorkspaceVolume(org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume) OnFailure(org.csanchez.jenkins.plugins.kubernetes.pod.retention.OnFailure) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with SnippetizerTester

use of org.jenkinsci.plugins.workflow.cps.SnippetizerTester in project workflow-basic-steps-plugin by jenkinsci.

the class CoreWrapperStepTest method useWrapper.

@Test
public void useWrapper() throws Throwable {
    sessions.then(j -> {
        new SnippetizerTester(j).assertRoundTrip(new CoreWrapperStep(new MockWrapper()), "mock {\n    // some block\n}");
        Map<String, String> slaveEnv = new HashMap<>();
        if (Functions.isWindows()) {
            slaveEnv.put("PATH", "c:\\windows\\System32");
        } else {
            slaveEnv.put("PATH", "/usr/bin:/bin");
        }
        slaveEnv.put("HOME", "/home/jenkins");
        createSpecialEnvSlave(j, "slave", "", slaveEnv);
        WorkflowJob p = j.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("node('slave') {mock {semaphore 'restarting'; echo \"groovy PATH=${env.PATH}:\"; " + (Functions.isWindows() ? "bat 'echo shell PATH=%PATH%:'}}" : "sh 'echo shell PATH=$PATH:'}}"), true));
        WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
        SemaphoreStep.waitForStart("restarting/1", b);
    });
    sessions.then(j -> {
        SemaphoreStep.success("restarting/1", null);
        WorkflowJob p = j.jenkins.getItemByFullName("p", WorkflowJob.class);
        WorkflowRun b = p.getLastBuild();
        j.assertBuildStatusSuccess(j.waitForCompletion(b));
        String expected = Functions.isWindows() ? "/home/jenkins/extra/bin;c:\\windows\\System32" : "/home/jenkins/extra/bin:/usr/bin:/bin";
        j.assertLogContains("groovy PATH=" + expected + ":", b);
        j.assertLogContains("shell PATH=" + expected + ":", b);
        j.assertLogContains("ran DisposerImpl", b);
        j.assertLogNotContains("CoreWrapperStep", b);
    });
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) HashMap(java.util.HashMap) SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 3 with SnippetizerTester

use of org.jenkinsci.plugins.workflow.cps.SnippetizerTester in project junit-plugin by jenkinsci.

the class JUnitResultsStepTest method configRoundTrip.

@Test
public void configRoundTrip() throws Exception {
    SnippetizerTester st = new SnippetizerTester(rule);
    JUnitResultsStep step = new JUnitResultsStep("**/target/surefire-reports/TEST-*.xml");
    st.assertRoundTrip(step, "junit '**/target/surefire-reports/TEST-*.xml'");
    step.setAllowEmptyResults(true);
    st.assertRoundTrip(step, "junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'");
    step.setHealthScaleFactor(2.0);
    st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'");
    MockTestDataPublisher publisher = new MockTestDataPublisher("testing");
    step.setTestDataPublishers(Collections.singletonList(publisher));
    st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'");
    step.setSkipMarkingBuildUnstable(true);
    st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, skipMarkingBuildUnstable: true, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'");
}
Also used : SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) TestResultTest(hudson.tasks.junit.TestResultTest) Test(org.junit.Test)

Example 4 with SnippetizerTester

use of org.jenkinsci.plugins.workflow.cps.SnippetizerTester in project azure-keyvault-plugin by jenkinsci.

the class AzureKeyVaultStepTest method configRoundTrip.

@Test
public void configRoundTrip() throws Exception {
    SnippetizerTester st = new SnippetizerTester(j);
    List<AzureKeyVaultSecret> secrets = Collections.singletonList(new AzureKeyVaultSecret("Secret", "hi", "HI"));
    AzureKeyVaultStep step = new AzureKeyVaultStep(secrets);
    st.assertRoundTrip(step, "azureKeyVault([[envVariable: 'HI', name: 'hi', secretType: 'Secret']]) {\n" + "    // some block\n" + "}");
    step.setCredentialID("credId");
    st.assertRoundTrip(step, "azureKeyVault(credentialID: 'credId', secrets: [[envVariable: 'HI', name: 'hi', secretType: 'Secret']]) {\n" + "    // some block\n" + "}");
    step.setKeyVaultURL("https://mine.vault.azure.net");
    st.assertRoundTrip(step, "azureKeyVault(credentialID: 'credId', keyVaultURL: 'https://mine.vault.azure.net', secrets: [[envVariable: 'HI', name: 'hi', secretType: 'Secret']]) {\n" + "    // some block\n" + "}");
}
Also used : SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) Test(org.junit.Test)

Example 5 with SnippetizerTester

use of org.jenkinsci.plugins.workflow.cps.SnippetizerTester in project copyartifact-plugin by jenkinsci.

the class CopyArtifactPermissionPropertyTest method configProps.

@Test
public void configProps() throws Exception {
    JobProperty<?> property = new CopyArtifactPermissionProperty("project1,project2");
    SnippetizerTester tester = new SnippetizerTester(j);
    tester.assertRoundTrip(new JobPropertyStep(Collections.singletonList(property)), "properties([copyArtifactPermission('project1,project2')])");
}
Also used : SnippetizerTester(org.jenkinsci.plugins.workflow.cps.SnippetizerTester) JobPropertyStep(org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep) Test(org.junit.Test)

Aggregations

SnippetizerTester (org.jenkinsci.plugins.workflow.cps.SnippetizerTester)6 Test (org.junit.Test)6 ThrottleStep (hudson.plugins.throttleconcurrents.pipeline.ThrottleStep)1 TestResultTest (hudson.tasks.junit.TestResultTest)1 HashMap (java.util.HashMap)1 OnFailure (org.csanchez.jenkins.plugins.kubernetes.pod.retention.OnFailure)1 DynamicPVCWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.DynamicPVCWorkspaceVolume)1 EmptyDirWorkspaceVolume (org.csanchez.jenkins.plugins.kubernetes.volumes.workspace.EmptyDirWorkspaceVolume)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 JobPropertyStep (org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep)1 Issue (org.jvnet.hudson.test.Issue)1