Skip to content

Commit

Permalink
adjust logging, add no existing file container test (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
MxEh-TT committed Aug 7, 2023
1 parent 56a95f1 commit 425811d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CheckPackageResult implements Serializable{
String toString() {
String str = """Found : ${size} issues\n"""
for (issue in issues){
str += issue.toString() + "\n"
str += issue.getFileName() +" "+ issue.getMessage() + "\n"
}
return str.stripIndent().trim()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class CheckPackageStep extends Step {
CheckReport packageCheck = apiClient.runPackageCheck(this.testCasePath)
CheckPackageResult result = new CheckPackageResult( packageCheck.getSize(), packageCheck.getIssues())
if (result.getSize() != 0){
throw new Exception(result.toString())
throw new RuntimeException(result.toString())
}
else{
listener.logger.println(result.toString())
listener.logger.println("Package Checks Success")
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,42 @@ class ETContainerTest extends ContainerTest {

def "Perform check step"() {
given: "a test execution pipeline"
String script = """
node {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttCheckPackage testCasePath: 'test.pkg'
String script = """
node {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttCheckPackage testCasePath: 'test.pkg'
}
}
}
""".stripIndent()
WorkflowJob job = jenkins.createProject(WorkflowJob.class, "pipeline")
job.setDefinition(new CpsFlowDefinition(script, true))
""".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)
WorkflowRun run = jenkins.buildAndAssertStatus(Result.SUCCESS, job)

then: "expect successful test completion"
jenkins.assertLogContains("Found : 0 issues",run)
jenkins.assertLogContains("Executing checks for",run)
jenkins.assertLogContains("Package Checks Success", run)
}

def "Perform check step on non-existing package"() {
given: "a test execution pipeline"
String script = """
node {
withEnv(['ET_API_HOSTNAME=${etContainer.host}', 'ET_API_PORT=${etContainer.getMappedPort(ET_PORT)}']) {
ttCheckPackage testCasePath: 'test.pkg'
}
}
""".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 error"
jenkins.assertLogContains("BAD REQUEST",run)
jenkins.assertLogNotContains("Package Checks Success", run)
}

def "Execute test case"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,29 @@ class CheckPackageStepIT extends IntegrationTestBase {

def 'Default config round trip'() {
given:
CheckPackageStep before = new CheckPackageStep("test.pkg")
CheckPackageStep before = new CheckPackageStep("test.pkg")
when:
GenerateReportsStep after = new StepConfigTester(jenkins).configRoundTrip(before)
CheckPackageStep after = new StepConfigTester(jenkins).configRoundTrip(before)
then:
jenkins.assertEqualDataBoundBeans(before, after)
jenkins.assertEqualDataBoundBeans(before, after)
}

def 'Snippet generator'() {
given:
SnippetizerTester st = new SnippetizerTester(jenkins)
SnippetizerTester st = new SnippetizerTester(jenkins)
when:
CheckPackageStep step = new CheckPackageStep("test.pkg")
CheckPackageStep step = new CheckPackageStep("test.pkg")
then:
st.assertRoundTrip(step, "ttCheckPackage 'test.pkg'")
st.assertRoundTrip(step, "ttCheckPackage 'test.pkg'")
}

def 'Run pipeline'() {
given:
WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline')
job.setDefinition(new CpsFlowDefinition("node { ttCheckPackage 'test.pkg' }", true))
WorkflowJob job = jenkins.createProject(WorkflowJob.class, 'pipeline')
job.setDefinition(new CpsFlowDefinition("node { ttCheckPackage 'test.pkg' }", true))
expect:
WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get())
jenkins.assertLogContains('Executing checks for', run)
WorkflowRun run = jenkins.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get())
jenkins.assertLogContains('Executing checks for', run)
jenkins.assertLogContains("Package Checks Success", run)
}
}

0 comments on commit 425811d

Please sign in to comment.