Skip to content

Commit

Permalink
[JENKINS-27057] Correcting mistake in 6140881717bf937ecb42bf77ec11dcc…
Browse files Browse the repository at this point in the history
…208bedd0c.

Log text was being doubly copied.
Originally-Committed-As: 6de84edb0dd337b2179cb3f1bca1de396c10907d
  • Loading branch information
jglick committed Jan 12, 2016
1 parent 7a00247 commit f9bd8b7
Showing 1 changed file with 70 additions and 0 deletions.
@@ -0,0 +1,70 @@
/*
* The MIT License
*
* Copyright 2016 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.workflow.steps;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jenkinsci.plugins.workflow.actions.LogAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Rule;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.JenkinsRule;

public class EchoStepTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();

@Test public void smokes() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'hello there'", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
List<LogAction> logActions = new ArrayList<LogAction>();
for (FlowNode n : new FlowGraphWalker(b.getExecution())) {
LogAction la = n.getAction(LogAction.class);
if (la != null) {
logActions.add(la);
}
}
assertEquals(1, logActions.size());
StringWriter w = new StringWriter();
logActions.get(0).getLogText().writeLogTo(0, w);
assertEquals("hello there", w.toString().trim());
Matcher m = Pattern.compile("hello there").matcher(JenkinsRule.getLog(b));
assertTrue("message printed once", m.find());
assertFalse("message not printed twice", m.find());
}

}

0 comments on commit f9bd8b7

Please sign in to comment.