Просмотр исходного кода

canPushFilesSuccessfully integration test.

Winston Li 11 лет назад
Родитель
Сommit
4781a78926

+ 41 - 14
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java

@@ -35,6 +35,9 @@ public class WLGitBridgeIntegrationTest {
                 put("canCloneMultipleRepositories", new HashMap<String, SnapshotAPIState>() {{
                     put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneMultipleRepositories/state/state.json")).build());
                 }});
+                put("cannotCloneAProtectedProject", new HashMap<String, SnapshotAPIState>() {{
+                    put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAProtectedProject/state/state.json")).build());
+                }});
                 put("canPullAModifiedTexFile", new HashMap<String, SnapshotAPIState>() {{
                     put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
                     put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
@@ -59,8 +62,8 @@ public class WLGitBridgeIntegrationTest {
                     put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/base/state.json")).build());
                     put("withDeletedNestedFiles", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullDeletedNestedFiles/withDeletedNestedFiles/state.json")).build());
                 }});
-                put("cannotCloneAProtectedProject", new HashMap<String, SnapshotAPIState>() {{
-                    put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAProtectedProject/state/state.json")).build());
+                put("canPushFilesSuccessfully", new HashMap<String, SnapshotAPIState>() {{
+                    put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canPushFilesSuccessfully/state/state.json")).build());
                 }});
             }};
 
@@ -108,6 +111,28 @@ public class WLGitBridgeIntegrationTest {
         assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneMultipleRepositories/state/testproj2"), testproj2Dir.toPath()));
     }
 
+
+    private static final String EXPECTED_OUT_PROTECTED =
+            "Cloning into 'protected'...\n" +
+                    "fatal: remote error: Your project is protected, and can't be cloned (yet).\n";
+    @Test
+    public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException {
+        MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile());
+        server.start();
+        server.setState(states.get("cannotCloneAProtectedProject").get("state"));
+        GitBridgeApp wlgb = new GitBridgeApp(new String[] {
+                makeConfigFile(33861, 3861)
+        });
+        wlgb.run();
+        File dir = folder.newFolder();
+        Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir);
+        String output = Util.fromStream(git.getErrorStream());
+        int exitCode = git.waitFor();
+        assertEquals(128, exitCode);
+        assertEquals(EXPECTED_OUT_PROTECTED, output);
+        wlgb.stop();
+    }
+
     @Test
     public void canPullAModifiedTexFile() throws IOException, GitAPIException, InterruptedException {
         MockSnapshotServer server = new MockSnapshotServer(3859, getResource("/canPullAModifiedTexFile").toFile());
@@ -246,26 +271,28 @@ public class WLGitBridgeIntegrationTest {
         assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPullDeletedNestedFiles/withDeletedNestedFiles/testproj"), testprojDir.toPath()));
     }
 
-
-    private static final String EXPECTED_OUT_PROTECTED =
-            "Cloning into 'protected'...\n" +
-            "fatal: remote error: Your project is protected, and can't be cloned (yet).\n";
     @Test
-    public void cannotCloneAProtectedProject() throws IOException, GitAPIException, InterruptedException {
-        MockSnapshotServer server = new MockSnapshotServer(3861, getResource("/cannotCloneAProtectedProject").toFile());
+    public void canPushFilesSuccessfully() throws IOException, GitAPIException, InterruptedException {
+        MockSnapshotServer server = new MockSnapshotServer(3866, getResource("/canPushFilesSuccessfully").toFile());
         server.start();
-        server.setState(states.get("cannotCloneAProtectedProject").get("state"));
+        server.setState(states.get("canPushFilesSuccessfully").get("state"));
         GitBridgeApp wlgb = new GitBridgeApp(new String[] {
-                makeConfigFile(33861, 3861)
+                makeConfigFile(33866, 3866)
         });
         wlgb.run();
         File dir = folder.newFolder();
-        Process git = runtime.exec("git clone http://127.0.0.1:33861/protected.git", null, dir);
-        String output = Util.fromStream(git.getErrorStream());
+        Process git = runtime.exec("git clone http://127.0.0.1:33866/testproj.git", null, dir);
         int exitCode = git.waitFor();
-        assertEquals(128, exitCode);
-        assertEquals(EXPECTED_OUT_PROTECTED, output);
+        File testprojDir = new File(dir, "testproj");
+        assertEquals(0, exitCode);
+        assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canPushFilesSuccessfully/state/testproj"), testprojDir.toPath()));
+        runtime.exec("touch push.tex", null, testprojDir).waitFor();
+        runtime.exec("git add -A", null, testprojDir).waitFor();
+        runtime.exec("git commit -m \"push\"", null, testprojDir).waitFor();
+        Process gitPush = runtime.exec("git push", null, testprojDir);
+        int pushExitCode = gitPush.waitFor();
         wlgb.stop();
+        assertEquals(0, pushExitCode);
     }
 
     private String makeConfigFile(int port, int apiPort) throws IOException {

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canCloneARepository/state/testproj/min_mean_wait_evm_7_eps_150dpi.png


+ 46 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/state.json

@@ -0,0 +1,46 @@
+[
+	{
+		"project": "testproj",
+		"getDoc": {
+			"versionID": 1,
+			"createdAt": "2014-11-30T18:40:58.123Z",
+			"email": "jdleesmiller+1@gmail.com",
+			"name": "John+1"
+		},
+		"getSavedVers": [
+        	{
+        		"versionID": 1,
+        		"comment": "added more info on doc GET and error details",
+        		"email": "jdleesmiller+1@gmail.com",
+        		"name": "John+1",
+        		"createdAt": "2014-11-30T18:47:01.333Z"
+        	}
+		],
+		"getForVers": [
+			{
+				"versionID": 1,
+				"srcs": [
+                    {
+                    	"content": "content\n",
+                    	"path": "main.tex"
+                    },
+                    {
+                    	"content": "This text is from another file.",
+                    	"path": "foo/bar/test.tex"
+                    }
+	            ],
+	            "atts": [
+	            	{
+	            		"url": "http://127.0.0.1:3866/state/testproj/min_mean_wait_evm_7_eps_150dpi.png",
+	            		"path": "min_mean_wait_evm_7_eps_150dpi.png"
+	            	}
+	            ]
+	        }
+		],
+		"push": "success",
+		"postback": {
+			"type": "success",
+			"versionID": 2
+		}
+	}
+]

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/foo/bar/test.tex

@@ -0,0 +1 @@
+This text is from another file.

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/main.tex

@@ -0,0 +1 @@
+content

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/canPushFilesSuccessfully/state/testproj/min_mean_wait_evm_7_eps_150dpi.png