]> source.dussan.org Git - gitblit.git/commitdiff
Add protect-refs unit tests for branch/tag creation/deletion. 7/head
authorPhilip L. McMahon <philip.l.mcmahon@gmail.com>
Sun, 5 Feb 2012 06:02:32 +0000 (22:02 -0800)
committerPhilip L. McMahon <philip.l.mcmahon@gmail.com>
Sun, 5 Feb 2012 06:02:32 +0000 (22:02 -0800)
tests/com/gitblit/tests/GroovyScriptTest.java

index b21c7e7d856ae980fed06211e32c7eecaf1af324..5051100a21a2749a8a3a692b6b600bfe489a9d9b 100644 (file)
@@ -88,6 +88,97 @@ public class GroovyScriptTest {
                assertTrue(m.message.contains("BIT"));\r
        }\r
        \r
+       @Test\r
+       public void testProtectRefsCreateBranch() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+       }\r
+       \r
+       @Test\r
+       public void testProtectRefsCreateTag() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+               assertEquals(0, logger.messages.size());\r
+       }\r
+       \r
+       @Test\r
+       public void testProtectRefsFastForward() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               commands.add(new ReceiveCommand(ObjectId\r
+                               .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+               assertEquals(0, logger.messages.size());\r
+       }\r
+       \r
+       @Test\r
+       public void testProtectRefsDeleteMasterBranch() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               ReceiveCommand command = new ReceiveCommand(ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+                               "refs/heads/master");\r
+               commands.add(command);\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+               assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
+               assertEquals(0, logger.messages.size());\r
+       }\r
+       \r
+       @Test\r
+       public void testProtectRefsDeleteOtherBranch() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               commands.add(new ReceiveCommand(ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+                               "refs/heads/other"));\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+               assertEquals(0, logger.messages.size());\r
+       }\r
+       \r
+       @Test\r
+       public void testProtectRefsDeleteTag() throws Exception {\r
+               MockGitblit gitblit = new MockGitblit();\r
+               MockLogger logger = new MockLogger();\r
+               List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+               ReceiveCommand command = new ReceiveCommand(ObjectId\r
+                               .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+                               "refs/tags/v1.0");\r
+               commands.add(command);\r
+               \r
+               RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());               \r
+\r
+               test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+               assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
+               assertEquals(0, logger.messages.size());\r
+       }\r
+       \r
        @Test\r
        public void testBlockPush() throws Exception {\r
                MockGitblit gitblit = new MockGitblit();\r