diff --git a/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java b/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java index 2ea3fdde6f..2906b05cbe 100644 --- a/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java +++ b/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java @@ -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; @@ -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, @@ -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 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 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 == ';'; } } diff --git a/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java b/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java index 7297447ce0..ecba353e8b 100644 --- a/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java +++ b/src/test/java/org/jenkinsci/plugins/gitclient/GitAPITestCase.java @@ -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(); @@ -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(); @@ -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 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 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");