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

Migrated Tests from GitAPITestCase to GitAPITest #668

Merged
merged 8 commits into from
Feb 20, 2021
89 changes: 88 additions & 1 deletion src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkinsci.plugins.gitclient;

import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
Expand All @@ -11,12 +12,15 @@
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
* Git API Tests, eventual replacement for GitAPITestCase,
Expand Down Expand Up @@ -104,7 +108,90 @@ public void testGetRemoteUrl() throws Exception {
workspace.launchCommand("git", "remote", "add", "origin", "https://github.com/jenkinsci/git-client-plugin.git");
workspace.launchCommand("git", "remote", "add", "ndeloof", "git@github.com:ndeloof/git-client-plugin.git");
String remoteUrl = workspace.getGitClient().getRemoteUrl("origin");
assertEquals("unexepected remote URL " + remoteUrl, "https://github.com/jenkinsci/git-client-plugin.git", remoteUrl);
assertEquals("unexepected remote URL " + remoteUrl, "https://github.com/jenkinsci/git-client-plugin.git",
remoteUrl);
}

@Test
public void testEmptyComment() throws Exception {
workspace.commitEmpty("init-empty-comment-to-tag-fails-on-windows");
if (isWindows()) {
workspace.getGitClient().tag("non-empty-comment", "empty-tag-comment-fails-on-windows");
} else {
workspace.getGitClient().tag("empty-comment", "");
}
}

@Test
public void testCreateBranch() throws Exception {
workspace.commitEmpty("init");
workspace.getGitClient().branch("test");
String branches = workspace.launchCommand("git", "branch", "-l");
assertTrue("master branch not listed", branches.contains("master"));
assertTrue("test branch not listed", branches.contains("test"));
}

@Test
public void testDeleteBranch() throws Exception {
workspace.commitEmpty("init");
workspace.getGitClient().branch("test");
workspace.getGitClient().deleteBranch("test");
String branches = workspace.launchCommand("git", "branch", "-l");
assertFalse("deleted test branch still present", branches.contains("test"));
try {
workspace.getGitClient().deleteBranch("test");
assertTrue("cgit did not throw an exception", workspace.getGitClient() instanceof JGitAPIImpl);
} catch (GitException ge) {
assertEquals("Could not delete branch test", ge.getMessage());
}
}

@Test
public void testDeleteTag() throws Exception {
workspace.commitEmpty("init");
workspace.tag("test");
workspace.tag("another");
workspace.getGitClient().deleteTag("test");
String tags = workspace.launchCommand("git", "tag");
assertFalse("deleted test tag still present", tags.contains("test"));
assertTrue("expected tag not listed", tags.contains("another"));
try {
workspace.getGitClient().deleteTag("test");
assertTrue("cgit did not throw an exception", workspace.getGitClient() instanceof JGitAPIImpl);
} catch (GitException ge) {
assertEquals("Could not delete tag test", ge.getMessage());
}
}

@Test
public void testListTagsWithFilter() throws Exception {
workspace.commitEmpty("init");
workspace.tag("test");
workspace.tag("another_test");
workspace.tag("yet_another");
Set<String> tags = workspace.getGitClient().getTagNames("*test");
assertTrue("expected tag test not listed", tags.contains("test"));
assertTrue("expected tag another_tag not listed", tags.contains("another_test"));
assertFalse("unexpected tag yet_another listed", tags.contains("yet_another"));
}

@Test
public void testListTagsWithoutFilter() throws Exception {
workspace.commitEmpty("init");
workspace.tag("test");
workspace.tag("another_test");
workspace.tag("yet_another");
Set<String> allTags = workspace.getGitClient().getTagNames(null);
assertTrue("tag 'test' not listed", allTags.contains("test"));
assertTrue("tag 'another_test' not listed", allTags.contains("another_test"));
assertTrue("tag 'yet_another' not listed", allTags.contains("yet_another"));
}

/**
* inline ${@link hudson.Functions#isWindows()} to prevent a transient remote classloader issue
*/
private boolean isWindows() {
return File.pathSeparatorChar == ';';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -833,25 +833,6 @@ public void test_getTagNames_supports_slashes_in_tag_names() throws Exception {
}
}

public void test_empty_comment() throws Exception {
w.init();
w.commitEmpty("init-empty-comment-to-tag-fails-on-windows");
if (isWindows()) {
w.git.tag("non-empty-comment", "empty-tag-comment-fails-on-windows");
} else {
w.git.tag("empty-comment", "");
}
}

public void test_create_branch() throws Exception {
w.init();
w.commitEmpty("init");
w.git.branch("test");
String branches = w.launchCommand("git", "branch", "-l");
assertTrue("master branch not listed", branches.contains("master"));
assertTrue("test branch not listed", branches.contains("test"));
}

@Issue("JENKINS-34309")
public void test_list_branches() throws Exception {
w.init();
Expand Down Expand Up @@ -950,21 +931,6 @@ public void test_list_branches_containing_ref() throws Exception {
assertEquals(3, branches.size());
}

public void test_delete_branch() throws Exception {
w.init();
w.commitEmpty("init");
w.git.branch("test");
w.git.deleteBranch("test");
String branches = w.launchCommand("git", "branch", "-l");
assertFalse("deleted test branch still present", branches.contains("test"));
try {
w.git.deleteBranch("test");
assertTrue("cgit did not throw an exception", w.git instanceof JGitAPIImpl);
} catch (GitException ge) {
assertEquals("Could not delete branch test", ge.getMessage());
}
}

@Issue("JENKINS-23299")
public void test_create_tag() throws Exception {
w.init();
Expand Down Expand Up @@ -1012,47 +978,6 @@ public void test_create_tag() throws Exception {
assertNull("did not expect reference for invalid tag but got : " + invalidTagId, invalidTagId);
}

public void test_delete_tag() throws Exception {
w.init();
w.commitEmpty("init");
w.tag("test");
w.tag("another");
w.git.deleteTag("test");
String tags = w.launchCommand("git", "tag");
assertFalse("deleted test tag still present", tags.contains("test"));
assertTrue("expected tag not listed", tags.contains("another"));
try {
w.git.deleteTag("test");
assertTrue("cgit did not throw an exception", w.git instanceof JGitAPIImpl);
} catch (GitException ge) {
assertEquals("Could not delete tag test", ge.getMessage());
}
}

public void test_list_tags_with_filter() throws Exception {
w.init();
w.commitEmpty("init");
w.tag("test");
w.tag("another_test");
w.tag("yet_another");
Set<String> tags = w.git.getTagNames("*test");
assertTrue("expected tag test not listed", tags.contains("test"));
assertTrue("expected tag another_test not listed", tags.contains("another_test"));
assertFalse("unexpected yet_another tag listed", tags.contains("yet_another"));
}

public void test_list_tags_without_filter() throws Exception {
w.init();
w.commitEmpty("init");
w.tag("test");
w.tag("another_test");
w.tag("yet_another");
Set<String> allTags = w.git.getTagNames(null);
assertTrue("tag 'test' not listed", allTags.contains("test"));
assertTrue("tag 'another_test' not listed", allTags.contains("another_test"));
assertTrue("tag 'yet_another' not listed", allTags.contains("yet_another"));
}

public void test_list_tags_star_filter() throws Exception {
w.init();
w.commitEmpty("init");
Expand Down