Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JENKINS-25256 Added project name and build number in the log #83

Merged
merged 1 commit into from Oct 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -80,7 +80,7 @@ public static List<Change> getChanges(AbstractBuild<?, ?> build) {
changeLink = link.toExternalForm();
}
} catch (IOException e) {
LOG.log(Level.WARNING, "Could not get changeset link", e);
LOG.log(Level.WARNING, "Could not get changeset link for: " + build.getProject().getFullDisplayName() + " " + build.getDisplayName(), e);
}
}
result.add(new Change(user, entry.getMsg(), entry.getCommitId(), changeLink));
Expand Down
33 changes: 32 additions & 1 deletion src/test/java/se/diabol/jenkins/pipeline/domain/ChangeTest.java
Expand Up @@ -19,14 +19,23 @@

import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.FakeChangeLogSCM;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockFolder;
import se.diabol.jenkins.pipeline.test.FakeRepositoryBrowserSCM;
import se.diabol.jenkins.pipeline.test.MeanFakeRepositoryBrowserSCM;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -37,6 +46,24 @@ public class ChangeTest {
@Rule
public JenkinsRule jenkins = new JenkinsRule();


private static Logger log = Logger.getLogger(Change.class.getName()); // matches the logger in the affected class
private static OutputStream logCapturingStream;
private static StreamHandler customLogHandler;

@Before
public void attachLogCapturer() {
logCapturingStream = new ByteArrayOutputStream();
Handler[] handlers = log.getParent().getHandlers();
customLogHandler = new StreamHandler(logCapturingStream, handlers[0].getFormatter());
log.addHandler(customLogHandler);
}

public String getTestCapturedLog() throws IOException {
customLogHandler.flush();
return logCapturingStream.toString();
}

@Test
public void testGetChangesNoBrowser() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("build");
Expand Down Expand Up @@ -77,7 +104,8 @@ public void testGetChangesWithBrowser() throws Exception {

@Test
public void testGetChangesWithBrowserThrowIOException() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("build");
MockFolder folder = jenkins.createFolder("Folder");
FreeStyleProject project = folder.createProject(FreeStyleProject.class, "build");
MeanFakeRepositoryBrowserSCM scm = new MeanFakeRepositoryBrowserSCM();
scm.addChange().withAuthor("test-user").withMsg("Fixed bug");
project.setScm(scm);
Expand All @@ -92,6 +120,9 @@ public void testGetChangesWithBrowserThrowIOException() throws Exception {
assertEquals("test-user", change.getAuthor().getName());
assertNull(change.getCommitId());
assertNull(change.getChangeLink());

String capturedLog = getTestCapturedLog();
Assert.assertTrue(capturedLog.contains("Could not get changeset link for: Folder » build #1"));
}


Expand Down