Skip to content
Permalink
Browse files

[JENKINS-23641] - Direct tests for the issue

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Oct 13, 2014
1 parent c4347f8 commit 25c1e85dd48d2bbe878aa7eb26f862b6e9f52971
@@ -52,12 +52,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

BuildData buildData = build.getAction(BuildData.class);
if (buildData == null) {
throw new IOException("Cannot retrieve Git metadata for the build");
throw new IOException(Messages.GitHubCommitNotifier_NoBuildDataError());
}
final Revision lastBuildRevision = buildData.getLastBuiltRevision();
final ObjectId sha1 = lastBuildRevision != null ? lastBuildRevision.getSha1() : null;
if (sha1 == null) { // Nowhere to report => fail the build
throw new IOException("Cannot determine sha1 of the commit. The status cannot be reported");
throw new IOException(Messages.GitHubCommitNotifier_NoLastRevisionError());
}

for (GitHubRepositoryName name : GitHubRepositoryNameContributor.parseAssociatedNames(build.getProject())) {
@@ -2,3 +2,5 @@ CommitNotifier.Success=Build {0} succeeded in {1}
CommitNotifier.Unstable=Build {0} found unstable in {1}
CommitNotifier.Failed=Build {0} failed in {1}
GitHubCommitNotifier.SettingCommitStatus=Setting commit status on GitHub for {0}
GitHubCommitNotifier.NoBuildDataError=Cannot retrieve Git metadata for the build
GitHubCommitNotifier.NoLastRevisionError=Cannot determine sha1 of the commit. The status cannot be reported
@@ -0,0 +1,51 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package com.cloudbees.jenkins;

import hudson.model.Build;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.plugins.git.GitSCM;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.JenkinsRule;

/**
* Tests for {@link GitHubCommitNotifier}.
* @author Oleg Nenashev <o.v.nenashev@gmail.com>
*/
public class GitHubCommitNotifierTest extends HudsonTestCase {

// @Rule
// public JenkinsRule r = new JenkinsRule();


@Test
@Bug(23641)
public void testNoBuildData() throws Exception, InterruptedException {
FreeStyleProject prj = createFreeStyleProject("23641_noBuildData");
prj.getPublishersList().add(new GitHubCommitNotifier());
Build b = prj.scheduleBuild2(0).get();
assertBuildStatus(Result.FAILURE, b);
assertLogContains(Messages.GitHubCommitNotifier_NoBuildDataError(), b);
}

@Test
@Bug(23641)
public void testNoBuildRevision() throws Exception, InterruptedException {
FreeStyleProject prj = createFreeStyleProject();
prj.setScm(new GitSCM("http://non.existent.git.repo.nowhere/repo.git"));
prj.getPublishersList().add(new GitHubCommitNotifier());
Build b = prj.scheduleBuild2(0).get();
assertBuildStatus(Result.FAILURE, b);
assertLogContains(Messages.GitHubCommitNotifier_NoLastRevisionError(), b);
}


}

0 comments on commit 25c1e85

Please sign in to comment.
You can’t perform that action at this time.