diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/SnapshotPostExceptionBuilder.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/SnapshotPostExceptionBuilder.java index 8fb9844c88..1ababc0272 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/SnapshotPostExceptionBuilder.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/push/exception/SnapshotPostExceptionBuilder.java @@ -18,7 +18,7 @@ public class SnapshotPostExceptionBuilder { } else if (errorCode.equals(CODE_ERROR_INVALID_FILES)) { return new InvalidFilesException(json); } else if (errorCode.equals(CODE_ERROR_INVALID_PROJECT)) { - return new uk.ac.ic.wlgitbridge.snapshot.getdoc.exception.InvalidProjectException(json); + return new InvalidProjectException(json); } else if (errorCode.equals(CODE_ERROR_UNKNOWN)) { return new UnexpectedErrorException(json); } else { diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java index 7893ba4216..7d7061634b 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest.java @@ -79,6 +79,9 @@ public class WLGitBridgeIntegrationTest { put("pushFailsOnInvalidProject", new HashMap() {{ put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnInvalidProject/state/state.json")).build()); }}); + put("pushFailsOnUnexpectedError", new HashMap() {{ + put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/pushFailsOnUnexpectedError/state/state.json")).build()); + }}); }}; @Rule @@ -456,6 +459,44 @@ public class WLGitBridgeIntegrationTest { assertEquals(EXPECTED_OUT_PUSH_INVALID_PROJECT, actual); } + + private static final List EXPECTED_OUT_PUSH_UNEXPECTED_ERROR = + Arrays.asList( + "remote: error: Overleaf error", + "remote: hint: There was an internal error with the Overleaf server.", + "remote: hint: Please contact Overleaf.", + "To http://127.0.0.1:33871/testproj.git", + "! [remote rejected] master -> master (Overleaf error)", + "error: failed to push some refs to 'http://127.0.0.1:33871/testproj.git'" + ); + + /* this one prints a stack trace */ + @Test + public void pushFailsOnUnexpectedError() throws IOException, GitAPIException, InterruptedException { + MockSnapshotServer server = new MockSnapshotServer(3871, getResource("/pushFailsOnUnexpectedError").toFile()); + server.start(); + server.setState(states.get("pushFailsOnUnexpectedError").get("state")); + GitBridgeApp wlgb = new GitBridgeApp(new String[] { + makeConfigFile(33871, 3871) + }); + wlgb.run(); + File dir = folder.newFolder(); + Process git = runtime.exec("git clone http://127.0.0.1:33871/testproj.git", null, dir); + int exitCode = git.waitFor(); + File testprojDir = new File(dir, "testproj"); + assertEquals(0, exitCode); + assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/pushFailsOnUnexpectedError/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(1, pushExitCode); + List actual = Util.linesFromStream(gitPush.getErrorStream(), 2, "[K"); + assertEquals(EXPECTED_OUT_PUSH_UNEXPECTED_ERROR, actual); + } + private String makeConfigFile(int port, int apiPort) throws IOException { File wlgb = folder.newFolder(); File config = folder.newFile(); diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/state.json b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/state.json new file mode 100644 index 0000000000..4a2374f3f2 --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/state.json @@ -0,0 +1,45 @@ +[ + { + "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:3871/state/testproj/min_mean_wait_evm_7_eps_150dpi.png", + "path": "min_mean_wait_evm_7_eps_150dpi.png" + } + ] + } + ], + "push": "success", + "postback": { + "type": "error" + } + } +] \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/foo/bar/test.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/foo/bar/test.tex new file mode 100644 index 0000000000..046794f19a --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/foo/bar/test.tex @@ -0,0 +1 @@ +This text is from another file. \ No newline at end of file diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/main.tex b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/main.tex new file mode 100644 index 0000000000..d95f3ad14d --- /dev/null +++ b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/main.tex @@ -0,0 +1 @@ +content diff --git a/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/min_mean_wait_evm_7_eps_150dpi.png b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/min_mean_wait_evm_7_eps_150dpi.png new file mode 100644 index 0000000000..74e1fcd990 Binary files /dev/null and b/services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/pushFailsOnUnexpectedError/state/testproj/min_mean_wait_evm_7_eps_150dpi.png differ