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

Fix testAvoidRedundantFetchWithHonorRefSpec assertions #926

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/test/java/hudson/plugins/git/GitSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ public void testSpecificRefspecs() throws Exception {
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit in master");
// create branch and make initial commit
git.branch("foo");
git.checkout().branch("foo");
git.checkout().ref("master").branch("foo").execute();
commit(commitFile1, johnDoe, "Commit in foo");

build(projectWithMaster, Result.FAILURE);
Expand Down Expand Up @@ -392,8 +391,7 @@ public void testAvoidRedundantFetchWithoutHonorRefSpec() throws Exception {
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit in master");
// Add another branch 'foo'
git.branch("foo");
git.checkout().branch("foo");
git.checkout().ref("master").branch("foo").execute();
commit(commitFile1, johnDoe, "Commit in foo");

// Build will be success because the initial clone disregards refspec and fetches all branches
Expand Down Expand Up @@ -433,20 +431,23 @@ public void testAvoidRedundantFetchWithHonorRefSpec() throws Exception {

// create initial commit
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit in master");
final String commitFile1SHA1a = commit(commitFile1, johnDoe, "Commit in master");
// Add another branch 'foo'
git.branch("foo");
git.checkout().branch("foo");
commit(commitFile1, johnDoe, "Commit in foo");
git.checkout().ref("master").branch("foo").execute();
final String commitFile1SHA1b = commit(commitFile1, johnDoe, "Commit in foo");

// Build will be failure because the initial clone regards refspec and fetches branch 'foo' only.
FreeStyleBuild build = build(projectWithMaster, Result.FAILURE);

FilePath childFile = returnFile(build);
assertNotNull(childFile);
// assert that no data is lost by avoidance of second fetch
assertThat(childFile.readToString(), not(containsString("master")));
assertThat("foo branch was not fetched", childFile.readToString(), containsString("foo"));
final String fetchHeadContents = childFile.readToString();
final List<String> buildLog = build.getLog(50);
assertThat("master branch was fetched: " + buildLog, fetchHeadContents, not(containsString("branch 'master'")));
assertThat("foo branch was not fetched: " + buildLog, fetchHeadContents, containsString("branch 'foo'"));
assertThat("master branch SHA1 '" + commitFile1SHA1a + "' fetched " + buildLog, fetchHeadContents, not(containsString(commitFile1SHA1a)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great assertion to exactly map the SHA1.

assertThat("foo branch SHA1 '" + commitFile1SHA1b + "' was not fetched " + buildLog, fetchHeadContents, containsString(commitFile1SHA1b));
assertRedundantFetchIsSkipped(build, refSpec);

assertThat(build.getResult(), is(Result.FAILURE));
Expand Down Expand Up @@ -570,8 +571,7 @@ public void testSpecificRefspecsWithoutCloneOption() throws Exception {
final String commitFile1 = "commitFile1";
commit(commitFile1, johnDoe, "Commit in master");
// create branch and make initial commit
git.branch("foo");
git.checkout().branch("foo");
git.checkout().ref("master").branch("foo").execute();
commit(commitFile1, johnDoe, "Commit in foo");

build(projectWithMaster, Result.SUCCESS); /* If clone refspec had been honored, this would fail */
Expand Down