Skip to content

Commit

Permalink
add testing for new step (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
MxEh-TT committed Jul 15, 2024
1 parent 91ae359 commit 7303d28
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ class ProvideReportLogsStep extends Step {

@Override
List<String> call() throws IOException {
listener.logger.println("Providing ecu.test report logs to jenkins.")
List<String> logs = []
RestApiClient apiClient = RestApiClientFactory.getRestApiClient(envVars.get('ET_API_HOSTNAME'), envVars.get('ET_API_PORT'))
listener.logger.println("ProvideReportLogsStep ...")
reportIds = apiClient.getAllReportIds()

if (reportIds == null || reportIds.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,43 @@ abstract class ETContainerTest extends ContainerTest {
then: "expect successful test and upload completion"
jenkins.assertLogContains("-> FINISHED", run)
}

def "Perform provide report logs step with no reports"() {
given: "a test execution pipeline"
String script = """
node {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttRunPackage testCasePath: 'test.pkg'
ttProvideReportLogs()
}
}
""".stripIndent()
WorkflowJob job = jenkins.createProject(WorkflowJob.class, "pipeline")
job.setDefinition(new CpsFlowDefinition(script, true))
when: "scheduling a new build"
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test completion"
jenkins.assertLogContains("Providing ecu.test report logs to jenkins.", run)
jenkins.assertLogContains("[WARNING] No report files returned by ecu.test", run)
}

def "Perform provide report logs step with reports"() {
given: "a test execution pipeline"
String script = """
node {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttProvideReportLogs()
}
}
""".stripIndent()
WorkflowJob job = jenkins.createProject(WorkflowJob.class, "pipeline")
job.setDefinition(new CpsFlowDefinition(script, true))
when: "scheduling a new build"
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test completion"
jenkins.assertLogContains("Providing ecu.test report logs to jenkins.", run)
jenkins.assertLogContains("Adding report logs to artifacts", run)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package de.tracetronic.jenkins.plugins.ecutestexecution.steps

import de.tracetronic.jenkins.plugins.ecutestexecution.ETInstallation
import de.tracetronic.jenkins.plugins.ecutestexecution.IntegrationTestBase
import hudson.Functions
import hudson.model.Result
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester
import org.jenkinsci.plugins.workflow.job.WorkflowJob
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.steps.StepConfigTester
import org.jvnet.hudson.test.JenkinsRule

class ProvideReportLogStepIT extends IntegrationTestBase {
def setup() {
ETInstallation.DescriptorImpl etDescriptor = jenkins.jenkins
.getDescriptorByType(ETInstallation.DescriptorImpl.class)
String executablePath = Functions.isWindows() ? 'C:\\ecu.test\\ECU-TEST.exe' : 'bin/ecu-test'
etDescriptor.setInstallations(new ETInstallation('ecu.test', executablePath, JenkinsRule.NO_PROPERTIES))
}

def 'Default config round trip'() {
given:
ProvideReportLogsStep before = new ProvideReportLogsStep()
when:
ProvideReportLogsStep after = new StepConfigTester(jenkins).configRoundTrip(before)
then:
jenkins.assertEqualDataBoundBeans(before, after)
}
def 'Snippet generator'() {
given:
SnippetizerTester st = new SnippetizerTester(jenkins)
when:
ProvideReportLogsStep step = new ProvideReportLogsStep()
then:
st.assertRoundTrip(step, "ttProvideReportLogs()")
}

def 'Run pipeline'() {
given:
WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline')
job.setDefinition(new CpsFlowDefinition("node {ttProvideReportLogs()}", true))
expect:
WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get())
jenkins.assertLogContains("Providing ecu.test report logs to jenkins.", run)
}
}

0 comments on commit 7303d28

Please sign in to comment.