From f4e0c0de7326a24c9160086eb8eebf66fea39074 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 18 Jun 2018 12:35:02 +0000 Subject: [PATCH 01/11] Improve logs to help discerning what is being looked for and where --- .../java/hudson/plugins/textfinder/TextFinderPublisher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index d5c7026..3cc1159 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -128,7 +128,7 @@ private void findText(Run run, FilePath workspace, TaskListener listener) boolean foundText = false; if (alsoCheckConsoleOutput) { - logger.println("Checking console output"); + logger.println("Looking for pattern " + "'" + regexp + "'" + " in the console output"); foundText |= checkFile( run.getLogFile(), @@ -140,7 +140,7 @@ private void findText(Run run, FilePath workspace, TaskListener listener) // printing this when checking console output will cause the plugin // to find this line, which would be pointless. // doing this only when fileSet!=null to avoid - logger.println("Checking " + regexp); + logger.println("Looking for pattern " + "'" + regexp + "'" + " in the file " + "'" + build.getLogFile() + "'"); } final RemoteOutputStream ros = new RemoteOutputStream(logger); From b8b873846cbc0f0c07032930e7818f9a96aee5e9 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 18 Jun 2018 12:35:15 +0000 Subject: [PATCH 02/11] Update tests --- .../textfinder/TextFinderPublisherAgentTest.java | 4 ++-- .../TextFinderPublisherFreestyleTest.java | 8 ++++---- .../TextFinderPublisherPipelineTest.java | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index dc26bc1..85b0c5e 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -62,7 +62,7 @@ public void failureIfFoundInFileOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the file " + "'" + build.getLogFile() + "'", build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -79,7 +79,7 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern " + "'" + ECHO_UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index a24bd95..7906033 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -48,7 +48,7 @@ public void successIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -66,7 +66,7 @@ public void failureIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -85,7 +85,7 @@ public void unstableIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -98,7 +98,7 @@ public void notFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); rule.assertBuildStatus(Result.SUCCESS, build); } } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index 648abf3..1e63b4a 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -58,7 +58,7 @@ public void successIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt', succeedIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -72,7 +72,7 @@ public void failureIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -86,7 +86,7 @@ public void unstableIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt', unstableIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -114,7 +114,7 @@ public void notFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -127,7 +127,7 @@ public void successIfFoundInConsole() throws Exception { + "node {findText regexp: 'foobar', succeedIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -141,7 +141,7 @@ public void failureIfFoundInConsole() throws Exception { + "node {findText regexp: 'foobar', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -155,7 +155,7 @@ public void unstableIfFoundInConsole() throws Exception { + "node {findText regexp: 'foobar', unstableIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -182,7 +182,7 @@ public void notFoundInConsole() throws Exception { "node {findText regexp: 'foobar', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); rule.assertBuildStatus(Result.SUCCESS, build); } } From ae92ff33e41a569bf23cef307d6aa13b2fd61696 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Fri, 6 Jul 2018 11:16:40 +0100 Subject: [PATCH 03/11] Use the correct object to get log file --- .../java/hudson/plugins/textfinder/TextFinderPublisher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index 3cc1159..547537a 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -140,7 +140,7 @@ private void findText(Run run, FilePath workspace, TaskListener listener) // printing this when checking console output will cause the plugin // to find this line, which would be pointless. // doing this only when fileSet!=null to avoid - logger.println("Looking for pattern " + "'" + regexp + "'" + " in the file " + "'" + build.getLogFile() + "'"); + logger.println("Looking for pattern " + "'" + regexp + "'" + " in the file " + "'" + run.getLogFile() + "'"); } final RemoteOutputStream ros = new RemoteOutputStream(logger); From 85d38e55dfa9f991d7a7682cf3bda2da83f0640e Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Fri, 6 Jul 2018 11:25:20 +0100 Subject: [PATCH 04/11] mvn fmt:format --- .../plugins/textfinder/TextFinderPublisher.java | 13 +++++++++++-- .../textfinder/TextFinderPublisherAgentTest.java | 15 +++++++++++++-- .../TextFinderPublisherFreestyleTest.java | 12 ++++++++---- .../TextFinderPublisherPipelineTest.java | 16 ++++++++++++---- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index 547537a..7266416 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -128,7 +128,8 @@ private void findText(Run run, FilePath workspace, TaskListener listener) boolean foundText = false; if (alsoCheckConsoleOutput) { - logger.println("Looking for pattern " + "'" + regexp + "'" + " in the console output"); + logger.println( + "Looking for pattern " + "'" + regexp + "'" + " in the console output"); foundText |= checkFile( run.getLogFile(), @@ -140,7 +141,15 @@ private void findText(Run run, FilePath workspace, TaskListener listener) // printing this when checking console output will cause the plugin // to find this line, which would be pointless. // doing this only when fileSet!=null to avoid - logger.println("Looking for pattern " + "'" + regexp + "'" + " in the file " + "'" + run.getLogFile() + "'"); + logger.println( + "Looking for pattern " + + "'" + + regexp + + "'" + + " in the file " + + "'" + + run.getLogFile() + + "'"); } final RemoteOutputStream ros = new RemoteOutputStream(logger); diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index 85b0c5e..f9a7e1e 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -62,7 +62,16 @@ public void failureIfFoundInFileOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the file " + "'" + build.getLogFile() + "'", build); + rule.assertLogContains( + "Looking for pattern " + + "'" + + UNIQUE_TEXT + + "'" + + " in the file " + + "'" + + build.getLogFile() + + "'", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -79,7 +88,9 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + ECHO_UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains( + "Looking for pattern " + "'" + ECHO_UNIQUE_TEXT + "'" + " in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index 7906033..8b5d11c 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -48,7 +48,8 @@ public void successIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains( + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -66,7 +67,8 @@ public void failureIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains( + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -85,7 +87,8 @@ public void unstableIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains( + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -98,7 +101,8 @@ public void notFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains( + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); rule.assertBuildStatus(Result.SUCCESS, build); } } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index 1e63b4a..8d7e148 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -58,7 +58,9 @@ public void successIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt', succeedIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); + rule.assertLogContains( + "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -72,7 +74,9 @@ public void failureIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); + rule.assertLogContains( + "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -86,7 +90,9 @@ public void unstableIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt', unstableIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); + rule.assertLogContains( + "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -114,7 +120,9 @@ public void notFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", build); + rule.assertLogContains( + "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + build); rule.assertBuildStatus(Result.SUCCESS, build); } From d7829085721de9b85288abb7402dec49a1620326 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Fri, 6 Jul 2018 11:37:47 +0100 Subject: [PATCH 05/11] Fix wrong test --- .../plugins/textfinder/TextFinderPublisherPipelineTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index 8d7e148..32f8928 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -106,7 +106,9 @@ public void notBuiltIfFoundInFile() throws Exception { + "node {findText regexp: 'foobar', fileSet: 'out.txt', notBuiltIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking foobar", build); + rule.assertLogContains( + "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.NOT_BUILT, build); } From f58e8bd2c49df42e767b01246c306b9d66d395b1 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 9 Jul 2018 00:35:49 +0100 Subject: [PATCH 06/11] Fix wrong test --- .../hudson/plugins/textfinder/TextFinderPublisherAgentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index f9a7e1e..ecf2424 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -89,7 +89,7 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern " + "'" + ECHO_UNIQUE_TEXT + "'" + " in the console output", + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); From f26a1b6a6c1cb64a1fa81c1a6252a7bf8e8d1ebc Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 9 Jul 2018 00:39:28 +0100 Subject: [PATCH 07/11] mvn fmt:format --- .../plugins/textfinder/TextFinderPublisherAgentTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index ecf2424..452d71e 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -89,8 +89,7 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", - build); + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } From 32661ee992efa39a314fd9e82252735e12e118c6 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 9 Jul 2018 02:45:22 +0200 Subject: [PATCH 08/11] Fix wrong test --- .../plugins/textfinder/TextFinderPublisherPipelineTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index 32f8928..b2baf4b 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -179,7 +179,7 @@ public void notBuiltIfFoundInConsole() throws Exception { + "node {findText regexp: 'foobar', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Checking console output", build); + rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.NOT_BUILT, build); } From d9d842f9bf038aa8bdc3e010b70ba67889d94ffb Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Fri, 13 Jul 2018 16:23:38 +0000 Subject: [PATCH 09/11] Fix pattern appearing in console logs and use global variables in some tests --- .../textfinder/TextFinderPublisher.java | 22 ++- .../TextFinderPublisherAgentTest.java | 13 +- .../TextFinderPublisherFreestyleTest.java | 12 +- .../TextFinderPublisherPipelineTest.java | 131 +++++++++++++----- 4 files changed, 113 insertions(+), 65 deletions(-) diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index 7266416..328b8b8 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -128,8 +128,8 @@ private void findText(Run run, FilePath workspace, TaskListener listener) boolean foundText = false; if (alsoCheckConsoleOutput) { - logger.println( - "Looking for pattern " + "'" + regexp + "'" + " in the console output"); + // Do not mention the pattern we are looking for to avoid false positives + logger.println("Looking for a specific pattern in the console output"); foundText |= checkFile( run.getLogFile(), @@ -137,24 +137,20 @@ private void findText(Run run, FilePath workspace, TaskListener listener) logger, run.getCharset(), true); - } else { - // printing this when checking console output will cause the plugin - // to find this line, which would be pointless. - // doing this only when fileSet!=null to avoid + } + + final RemoteOutputStream ros = new RemoteOutputStream(logger); + + if (fileSet != null) { logger.println( "Looking for pattern " + "'" + regexp + "'" - + " in the file " + + " in the files at " + "'" - + run.getLogFile() + + fileSet + "'"); - } - - final RemoteOutputStream ros = new RemoteOutputStream(logger); - - if (fileSet != null) { foundText |= workspace.act(new FileChecker(ros, fileSet, regexp)); } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index 452d71e..d8b259f 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -63,15 +63,7 @@ public void failureIfFoundInFileOnAgent() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern " - + "'" - + UNIQUE_TEXT - + "'" - + " in the file " - + "'" - + build.getLogFile() - + "'", - build); + "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the files at", build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -88,8 +80,7 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index 8b5d11c..44de798 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -48,8 +48,7 @@ public void successIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -67,8 +66,7 @@ public void failureIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -87,8 +85,7 @@ public void unstableIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -101,8 +98,7 @@ public void notFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); rule.assertBuildStatus(Result.SUCCESS, build); } } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index b2baf4b..e331304 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -20,6 +20,7 @@ public class TextFinderPublisherPipelineTest { private static final String UNIQUE_TEXT = "foobar"; private static final String ECHO_UNIQUE_TEXT = "echo " + UNIQUE_TEXT; + private static final String fileSet = "out.txt"; @Rule public JenkinsRule rule = new JenkinsRule(); @@ -54,14 +55,22 @@ public void successIfFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {writeFile file: 'out.txt', text: 'foobar'}\n" - + "node {findText regexp: 'foobar', fileSet: 'out.txt', succeedIfFound: true}\n")); + "node {writeFile file: '" + + fileSet + + "', text: '" + + UNIQUE_TEXT + + "'}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', fileSet: '" + + fileSet + + "', succeedIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", build); - assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); + assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -70,14 +79,22 @@ public void failureIfFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {writeFile file: 'out.txt', text: 'foobar'}\n" - + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); + "node {writeFile file: '" + + fileSet + + "', text: '" + + UNIQUE_TEXT + + "'}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', fileSet: '" + + fileSet + + "'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", build); - assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); + assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -86,14 +103,22 @@ public void unstableIfFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {writeFile file: 'out.txt', text: 'foobar'}\n" - + "node {findText regexp: 'foobar', fileSet: 'out.txt', unstableIfFound: true}\n")); + "node {writeFile file: '" + + fileSet + + "', text: '" + + UNIQUE_TEXT + + "'}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', fileSet: '" + + fileSet + + "', unstableIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", build); - assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); + assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -102,14 +127,22 @@ public void notBuiltIfFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {writeFile file: 'out.txt', text: 'foobar'}\n" - + "node {findText regexp: 'foobar', fileSet: 'out.txt', notBuiltIfFound: true}\n")); + "node {writeFile file: '" + + fileSet + + "', text: '" + + UNIQUE_TEXT + + "'}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', fileSet: '" + + fileSet + + "', notBuiltIfFound: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", build); - assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); + assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.NOT_BUILT, build); } @@ -118,12 +151,18 @@ public void notFoundInFile() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {writeFile file: 'out.txt', text: 'foobaz'}\n" - + "node {findText regexp: 'foobar', fileSet: 'out.txt'}\n")); + "node {writeFile file: '" + + fileSet + + "', text: 'foobaz'}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', fileSet: '" + + fileSet + + "'}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern 'foobar' in the file " + "'" + build.getLogFile() + "'", + "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", build); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -133,11 +172,17 @@ public void successIfFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {isUnix() ? sh('echo foobar') : bat(\"prompt \\$G\\r\\necho foobar\")}\n" - + "node {findText regexp: 'foobar', succeedIfFound: true, alsoCheckConsoleOutput: true}\n")); + "node {isUnix() ? sh('" + + ECHO_UNIQUE_TEXT + + "') : bat(\"prompt \\$G\\r\\n" + + ECHO_UNIQUE_TEXT + + "\")}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', succeedIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -147,11 +192,17 @@ public void failureIfFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {isUnix() ? sh('echo foobar') : bat(\"prompt \\$G\\r\\necho foobar\")}\n" - + "node {findText regexp: 'foobar', alsoCheckConsoleOutput: true}\n")); + "node {isUnix() ? sh('" + + ECHO_UNIQUE_TEXT + + "') : bat(\"prompt \\$G\\r\\n" + + ECHO_UNIQUE_TEXT + + "\")}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -161,11 +212,17 @@ public void unstableIfFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {isUnix() ? sh('echo foobar') : bat(\"prompt \\$G\\r\\necho foobar\")}\n" - + "node {findText regexp: 'foobar', unstableIfFound: true, alsoCheckConsoleOutput: true}\n")); + "node {isUnix() ? sh('" + + ECHO_UNIQUE_TEXT + + "') : bat(\"prompt \\$G\\r\\n" + + ECHO_UNIQUE_TEXT + + "\")}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', unstableIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -175,11 +232,17 @@ public void notBuiltIfFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {isUnix() ? sh('echo foobar') : bat(\"prompt \\$G\\r\\necho foobar\")}\n" - + "node {findText regexp: 'foobar', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); + "node {isUnix() ? sh('" + + ECHO_UNIQUE_TEXT + + "') : bat(\"prompt \\$G\\r\\n" + + ECHO_UNIQUE_TEXT + + "\")}\n" + + "node {findText regexp: '" + + UNIQUE_TEXT + + "', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.NOT_BUILT, build); } @@ -189,10 +252,12 @@ public void notFoundInConsole() throws Exception { WorkflowJob project = rule.createProject(WorkflowJob.class, "pipeline"); project.setDefinition( new CpsFlowDefinition( - "node {findText regexp: 'foobar', alsoCheckConsoleOutput: true}\n")); + "node {findText regexp: '" + + UNIQUE_TEXT + + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for pattern 'foobar' in the console output", build); + rule.assertLogContains("Looking for a specific pattern in the console output", build); rule.assertBuildStatus(Result.SUCCESS, build); } } From 1341ff819e80b77904c8a1563f975266c5718a92 Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 8 Oct 2018 17:57:47 +0100 Subject: [PATCH 10/11] Improve logs to help discerning what is being looked for, when and where --- .../textfinder/TextFinderPublisher.java | 10 ++- .../TextFinderPublisherAgentTest.java | 14 +++- .../TextFinderPublisherFreestyleTest.java | 28 ++++++-- .../TextFinderPublisherPipelineTest.java | 70 ++++++++++++++++--- 4 files changed, 104 insertions(+), 18 deletions(-) diff --git a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java index 328b8b8..3653d2c 100644 --- a/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java +++ b/src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java @@ -129,7 +129,7 @@ private void findText(Run run, FilePath workspace, TaskListener listener) if (alsoCheckConsoleOutput) { // Do not mention the pattern we are looking for to avoid false positives - logger.println("Looking for a specific pattern in the console output"); + logger.println("[TextFinder plugin] Scanning console output..."); foundText |= checkFile( run.getLogFile(), @@ -137,13 +137,19 @@ private void findText(Run run, FilePath workspace, TaskListener listener) logger, run.getCharset(), true); + logger.println( + "[TextFinder plugin] Finished looking for pattern " + + "'" + + regexp + + "'" + + " in the console output"); } final RemoteOutputStream ros = new RemoteOutputStream(logger); if (fileSet != null) { logger.println( - "Looking for pattern " + "[TextFinder plugin] Looking for pattern " + "'" + regexp + "'" diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index d8b259f..fd00726 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -63,7 +63,12 @@ public void failureIfFoundInFileOnAgent() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the files at", build); + "[TextFinder plugin] Looking for pattern " + + "'" + + UNIQUE_TEXT + + "'" + + " in the files at", + build); assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); } @@ -80,7 +85,12 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index 44de798..c373e86 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -48,7 +48,12 @@ public void successIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -66,7 +71,12 @@ public void failureIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -85,7 +95,12 @@ public void unstableIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -98,7 +113,12 @@ public void notFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); rule.assertBuildStatus(Result.SUCCESS, build); } } diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index e331304..cf39e70 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -68,7 +68,12 @@ public void successIfFoundInFile() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", + "[TextFinder plugin] Looking for pattern '" + + UNIQUE_TEXT + + "' in the files at " + + "'" + + fileSet + + "'", build); assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.SUCCESS, build); @@ -92,7 +97,12 @@ public void failureIfFoundInFile() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", + "[TextFinder plugin] Looking for pattern '" + + UNIQUE_TEXT + + "' in the files at " + + "'" + + fileSet + + "'", build); assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.FAILURE, build); @@ -116,7 +126,12 @@ public void unstableIfFoundInFile() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", + "[TextFinder plugin] Looking for pattern '" + + UNIQUE_TEXT + + "' in the files at " + + "'" + + fileSet + + "'", build); assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.UNSTABLE, build); @@ -140,7 +155,12 @@ public void notBuiltIfFoundInFile() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", + "[TextFinder plugin] Looking for pattern '" + + UNIQUE_TEXT + + "' in the files at " + + "'" + + fileSet + + "'", build); assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false); rule.assertBuildStatus(Result.NOT_BUILT, build); @@ -162,7 +182,12 @@ public void notFoundInFile() throws Exception { WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); rule.assertLogContains( - "Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'", + "[TextFinder plugin] Looking for pattern '" + + UNIQUE_TEXT + + "' in the files at " + + "'" + + fileSet + + "'", build); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -182,7 +207,12 @@ public void successIfFoundInConsole() throws Exception { + "', succeedIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.SUCCESS, build); } @@ -202,7 +232,12 @@ public void failureIfFoundInConsole() throws Exception { + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.FAILURE, build); } @@ -222,7 +257,12 @@ public void unstableIfFoundInConsole() throws Exception { + "', unstableIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.UNSTABLE, build); } @@ -242,7 +282,12 @@ public void notBuiltIfFoundInConsole() throws Exception { + "', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true); rule.assertBuildStatus(Result.NOT_BUILT, build); } @@ -257,7 +302,12 @@ public void notFoundInConsole() throws Exception { + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("Looking for a specific pattern in the console output", build); + rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains( + "[TextFinder plugin] Finished looking for pattern '" + + UNIQUE_TEXT + + "' in the console output", + build); rule.assertBuildStatus(Result.SUCCESS, build); } } From 608539c6434f56b5289b2e1742f2b1bcdbfb02ca Mon Sep 17 00:00:00 2001 From: Jorge Marin Date: Mon, 8 Oct 2018 18:03:18 +0100 Subject: [PATCH 11/11] Fix missing argument --- .../textfinder/TextFinderPublisherAgentTest.java | 2 +- .../textfinder/TextFinderPublisherFreestyleTest.java | 8 ++++---- .../textfinder/TextFinderPublisherPipelineTest.java | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java index fd00726..02b6d6d 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherAgentTest.java @@ -85,7 +85,7 @@ public void failureIfFoundInConsoleOnAgent() throws Exception { agent.getNodeName(), agent.getNodeName()))); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java index c373e86..10a0023 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherFreestyleTest.java @@ -48,7 +48,7 @@ public void successIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -71,7 +71,7 @@ public void failureIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -95,7 +95,7 @@ public void unstableIfFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -113,7 +113,7 @@ public void notFoundInConsole() throws Exception { project.getPublishersList().add(textFinder); FreeStyleBuild build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT diff --git a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java index cf39e70..9758295 100644 --- a/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java +++ b/src/test/java/hudson/plugins/textfinder/TextFinderPublisherPipelineTest.java @@ -207,7 +207,7 @@ public void successIfFoundInConsole() throws Exception { + "', succeedIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -232,7 +232,7 @@ public void failureIfFoundInConsole() throws Exception { + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -257,7 +257,7 @@ public void unstableIfFoundInConsole() throws Exception { + "', unstableIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -282,7 +282,7 @@ public void notBuiltIfFoundInConsole() throws Exception { + "', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT @@ -302,7 +302,7 @@ public void notFoundInConsole() throws Exception { + "', alsoCheckConsoleOutput: true}\n")); WorkflowRun build = project.scheduleBuild2(0).get(); rule.waitForCompletion(build); - rule.assertLogContains("[TextFinder plugin] Scanning console output..."); + rule.assertLogContains("[TextFinder plugin] Scanning console output...", build); rule.assertLogContains( "[TextFinder plugin] Finished looking for pattern '" + UNIQUE_TEXT