Skip to content

Commit

Permalink
jenkinsci#185 Test annotating long log file in shortlog
Browse files Browse the repository at this point in the history
  • Loading branch information
tszmytka committed Aug 1, 2020
1 parent d04809e commit fac4722
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
12 changes: 11 additions & 1 deletion src/test/java/hudson/plugins/ansicolor/JenkinsTestSupport.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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;
Expand All @@ -11,6 +10,9 @@
import java.io.File;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
Expand All @@ -20,6 +22,10 @@ public class JenkinsTestSupport {
public RestartableJenkinsRule jenkinsRule = new RestartableJenkinsRule();
private static final int CONSOLE_TAIL_DEFAULT = 150;

protected void assertOutputOnRunningPipeline(String expectedOutput, String notExpectedOutput, String pipelineScript, boolean useShortLog) {
assertOutputOnRunningPipeline(Collections.singletonList(expectedOutput), Collections.singletonList(notExpectedOutput), pipelineScript, useShortLog);
}

protected void assertOutputOnRunningPipeline(Collection<String> expectedOutput, Collection<String> notExpectedOutput, String pipelineScript, boolean useShortLog) {
jenkinsRule.addStep(new Statement() {

Expand All @@ -38,4 +44,8 @@ public void evaluate() throws Throwable {
}
});
}

protected static String repeat(String s, int times) {
return IntStream.range(0, times).mapToObj(i -> s).collect(Collectors.joining());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,50 @@
import org.junit.Test;

import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ShortlogActionCreatorIntegrationTest extends JenkinsTestSupport {
private static final String AS_1K = repeat("a", 1024);
private static final String BS_1K = repeat("b", 1024);
private static final String CS_1K = repeat("c", 1024);
private static final String DS_1K = repeat("d", 1024);

@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 script = "ansiColor('xterm') {\n" +
repeat("echo '\033[32m" + AS_1K + "\033[0m'\n", 150) +
"}";
assertOutputOnRunningPipeline("<span style=\"color: #00CD00;\">" + AS_1K + "</span>", "\033", script, true);
}

// final String as10k = IntStream.range(0, 10 * 1024).mapToObj(i -> "a").collect(Collectors.joining());
@Test
public void canAnotateLongLogOutputInShortlogMultipleSteps() {
final String script = "echo '\033[32mBeginning\033[0m'\n" +
"ansiColor('vga') {\n" +
" echo '\033[32m" + as10k + "\033[0m'\n" +
repeat(" echo '\033[32m" + AS_1K + "\033[0m'\n", 10) +
"}\n" +
"ansiColor('xterm') {\n" +
" echo '\033[32m" + bs30k + "\033[0m'\n" +
repeat(" echo '\033[32m" + BS_1K + "\033[0m'\n", 30) +
"}\n" +
"ansiColor('css') {\n" +
" echo '\033[32m" + cs50k + "\033[0m'\n" +
" echo '\033[32m" + ds50k + "\033[0m'\n" +
repeat(" echo '\033[32m" + CS_1K + "\033[0m'\n", 50) +
repeat(" echo '\033[32m" + DS_1K + "\033[0m'\n", 50) +
"}\n" +
"echo 'End'";

assertOutputOnRunningPipeline(
Arrays.asList(
// "<span style=\"color: #00CD00;\">" + bs30k + "</span>",
"<span style=\"color: green;\">" + cs50k + "</span>",
"<span style=\"color: green;\">" + ds50k + "</span>",
"<span style=\"color: #00CD00;\">" + BS_1K + "</span>",
"<span style=\"color: green;\">" + CS_1K + "</span>",
"<span style=\"color: green;\">" + DS_1K + "</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"
"\033[32m" + AS_1K + "\033[0m",
"\033[32m" + BS_1K + "\033[0m",
"\033[32m" + CS_1K + "\033[0m",
"\033[32m" + DS_1K + "\033[0m"
),
script,
true
Expand Down

0 comments on commit fac4722

Please sign in to comment.