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}");
}
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);
});
}
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'");
}
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" + "}");
}
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')])");
}
Aggregations