forked from jenkinsci/ansicolor-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jenkinsci#185 Add integration test for annotating long log file while…
… in shortlog
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/test/java/hudson/plugins/ansicolor/JenkinsTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package hudson.plugins.ansicolor; | ||
|
||
import hudson.console.AnnotatedLargeText; | ||
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.runners.model.Statement; | ||
import org.jvnet.hudson.test.RestartableJenkinsRule; | ||
|
||
import java.io.File; | ||
import java.io.StringWriter; | ||
import java.util.Collection; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class JenkinsTestSupport { | ||
@Rule | ||
public RestartableJenkinsRule jenkinsRule = new RestartableJenkinsRule(); | ||
private static final int CONSOLE_TAIL_DEFAULT = 150; | ||
|
||
protected void assertOutputOnRunningPipeline(Collection<String> expectedOutput, Collection<String> notExpectedOutput, String pipelineScript, boolean useShortLog) { | ||
jenkinsRule.addStep(new Statement() { | ||
|
||
@Override | ||
public void evaluate() throws Throwable { | ||
final WorkflowJob project = jenkinsRule.j.jenkins.createProject(WorkflowJob.class, "p"); | ||
project.setDefinition(new CpsFlowDefinition(pipelineScript, true)); | ||
jenkinsRule.j.assertBuildStatusSuccess(project.scheduleBuild2(0)); | ||
StringWriter writer = new StringWriter(); | ||
final WorkflowRun lastBuild = project.getLastBuild(); | ||
final long start = useShortLog ? new File(lastBuild.getRootDir(), "log").length() - CONSOLE_TAIL_DEFAULT * 1024 : 0; | ||
assertTrue(lastBuild.getLogText().writeHtmlTo(start, writer) > 0); | ||
final String html = writer.toString().replaceAll("<!--.+?-->", ""); | ||
assertThat(html).contains(expectedOutput); | ||
assertThat(html).doesNotContain(notExpectedOutput); | ||
} | ||
}); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/hudson/plugins/ansicolor/action/ShortlogActionCreatorIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package hudson.plugins.ansicolor.action; | ||
|
||
import hudson.plugins.ansicolor.JenkinsTestSupport; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
public class ShortlogActionCreatorIntegrationTest extends JenkinsTestSupport { | ||
|
||
@Test | ||
public void canAnotateLongLogOutputInShortlog() { | ||
final String eol = System.lineSeparator(); | ||
final String as1k = IntStream.range(0, 1024).mapToObj(i -> "a").collect(Collectors.joining()); | ||
final String as10k = IntStream.range(0, 10 * 1024).mapToObj(i -> as1k + eol).collect(Collectors.joining()); | ||
final String bs1k = IntStream.range(0, 1024).mapToObj(i -> "b").collect(Collectors.joining()); | ||
final String bs30k = IntStream.range(0, 30).mapToObj(i -> bs1k + eol).collect(Collectors.joining()); | ||
final String cs1k = IntStream.range(0, 1024).mapToObj(i -> "c").collect(Collectors.joining()); | ||
final String cs50k = IntStream.range(0, 50).mapToObj(i -> cs1k + eol).collect(Collectors.joining()); | ||
final String ds1k = IntStream.range(0, 1024).mapToObj(i -> "d").collect(Collectors.joining()); | ||
final String ds50k = IntStream.range(0, 50).mapToObj(i -> ds1k + eol).collect(Collectors.joining()); | ||
|
||
// final String as10k = IntStream.range(0, 10 * 1024).mapToObj(i -> "a").collect(Collectors.joining()); | ||
final String script = "echo '\033[32mBeginning\033[0m'\n" + | ||
"ansiColor('vga') {\n" + | ||
" echo '\033[32m" + as10k + "\033[0m'\n" + | ||
"}\n" + | ||
"ansiColor('xterm') {\n" + | ||
" echo '\033[32m" + bs30k + "\033[0m'\n" + | ||
"}\n" + | ||
"ansiColor('css') {\n" + | ||
" echo '\033[32m" + cs50k + "\033[0m'\n" + | ||
" echo '\033[32m" + ds50k + "\033[0m'\n" + | ||
"}\n" + | ||
"echo 'End'"; | ||
|
||
assertOutputOnRunningPipeline( | ||
Arrays.asList( | ||
// "<span style=\"color: #00CD00;\">" + bs30k + "</span>", | ||
"<span style=\"color: green;\">" + cs50k + "</span>", | ||
"<span style=\"color: green;\">" + ds50k + "</span>", | ||
"End" | ||
), | ||
Arrays.asList( | ||
"Beginning", | ||
"<span style=\"color: #00AA00;\">a", | ||
"\033[32m" + as10k + "\033[0m", | ||
"\033[32m" + bs30k + "\033[0m", | ||
"\033[32m" + cs50k + "\033[0m", | ||
"\033[32m" + ds50k + "\033[0m" | ||
), | ||
script, | ||
true | ||
); | ||
} | ||
} |