diff --git a/src/tfvc/commands/findconflicts.ts b/src/tfvc/commands/findconflicts.ts index 3fdafe2c09..2aedacc877 100644 --- a/src/tfvc/commands/findconflicts.ts +++ b/src/tfvc/commands/findconflicts.ts @@ -98,7 +98,7 @@ export class FindConflicts implements ITfvcCommand { } public async ParseExeOutput(executionResult: IExecutionResult): Promise { - return this.ParseOutput(executionResult); + return await this.ParseOutput(executionResult); } } diff --git a/test/tfvc/commands/commandhelper.test.ts b/test/tfvc/commands/commandhelper.test.ts index 37b62e4f8f..191b84ebdb 100644 --- a/test/tfvc/commands/commandhelper.test.ts +++ b/test/tfvc/commands/commandhelper.test.ts @@ -98,7 +98,7 @@ describe("Tfvc-CommandHelper", function() { } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -115,7 +115,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.AuthenticationFailed); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -132,7 +132,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.NotATfvcRepository); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -149,7 +149,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.NotATfvcRepository); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -166,7 +166,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.RepositoryNotFound); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -183,7 +183,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.NotATfvcRepository); - assert.equal(err.message.indexOf(Strings.NotATfvcRepository), 0); + assert.isTrue(err.message.startsWith(Strings.NotATfvcRepository)); assert.equal(err.stdout, undefined); } }); @@ -200,7 +200,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.AuthenticationFailed); - assert.equal(err.message.indexOf(Strings.TokenNotAllScopes), 0); + assert.isTrue(err.message.startsWith(Strings.TokenNotAllScopes)); assert.equal(err.stdout, undefined); } }); @@ -217,7 +217,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.TfvcNotFound); - assert.equal(err.message.indexOf(Strings.TfInitializeFailureError), 0); + assert.isTrue(err.message.startsWith(Strings.TfInitializeFailureError)); assert.equal(err.stdout, undefined); } }); @@ -234,7 +234,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.FileNotInMappings); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -251,7 +251,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.FileNotInWorkspace); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); assert.equal(err.stdout, undefined); } }); @@ -268,7 +268,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.UnknownError); - assert.equal(err.message.indexOf("something bad"), 0); + assert.isTrue(err.message.startsWith("something bad")); assert.equal(err.stdout, undefined); } }); @@ -285,7 +285,7 @@ describe("Tfvc-CommandHelper", function() { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "cmd"); assert.equal(err.tfvcErrorCode, TfvcErrorCodes.UnknownError); - assert.equal(err.message.indexOf("something bad"), 0); + assert.isTrue(err.message.startsWith("something bad")); assert.equal(err.stdout, "something bad"); } }); diff --git a/test/tfvc/commands/findconflicts.test.ts b/test/tfvc/commands/findconflicts.test.ts index a7ab0b13b8..60b3b868ff 100644 --- a/test/tfvc/commands/findconflicts.test.ts +++ b/test/tfvc/commands/findconflicts.test.ts @@ -62,6 +62,12 @@ describe("Tfvc-FindConflictsCommand", function() { assert.deepEqual(cmd.GetOptions(), {}); }); + it("should verify GetExeOptions", function() { + let localPath: string = "/usr/alias/repo1"; + let cmd: FindConflicts = new FindConflicts(undefined, localPath); + assert.deepEqual(cmd.GetExeOptions(), {}); + }); + it("should verify arguments", function() { let localPath: string = "/usr/alias/repo1"; let cmd: FindConflicts = new FindConflicts(undefined, localPath); @@ -69,6 +75,13 @@ describe("Tfvc-FindConflictsCommand", function() { assert.equal(cmd.GetArguments().GetArgumentsForDisplay(), "resolve -noprompt " + localPath + " -recursive -preview"); }); + it("should verify Exe arguments", function() { + let localPath: string = "/usr/alias/repo1"; + let cmd: FindConflicts = new FindConflicts(undefined, localPath); + + assert.equal(cmd.GetExeArguments().GetArgumentsForDisplay(), "resolve -noprompt " + localPath + " -recursive -preview"); + }); + it("should verify arguments with context", function() { let localPath: string = "/usr/alias/repo1"; let cmd: FindConflicts = new FindConflicts(context, localPath); @@ -76,6 +89,13 @@ describe("Tfvc-FindConflictsCommand", function() { assert.equal(cmd.GetArguments().GetArgumentsForDisplay(), "resolve -noprompt -collection:" + collectionUrl + " ******** " + localPath + " -recursive -preview"); }); + it("should verify Exe arguments with context", function() { + let localPath: string = "/usr/alias/repo1"; + let cmd: FindConflicts = new FindConflicts(context, localPath); + + assert.equal(cmd.GetExeArguments().GetArgumentsForDisplay(), "resolve -noprompt ******** " + localPath + " -recursive -preview"); + }); + it("should verify parse output - no output", async function() { let localPath: string = "/usr/alias/repo1"; let cmd: FindConflicts = new FindConflicts(undefined, localPath); @@ -99,6 +119,7 @@ describe("Tfvc-FindConflictsCommand", function() { "addConflict.txt: Another item with the same name exists on the server\n" + "nameChange.txt: The item name has changed\n" + "nameAndContentChange.txt: The item name and content have changed\n" + + "anotherNameAndContentChange.txt: You have a conflicting pending change\n" + "contentChange2.txt: The item content has changed\n" + "deleted.txt: The item has already been deleted\n" + "branchEdit.txt: The source and target both have changes\n" + @@ -106,7 +127,7 @@ describe("Tfvc-FindConflictsCommand", function() { }; let results: IConflict[] = await cmd.ParseOutput(executionResult); - assert.equal(results.length, 8); + assert.equal(results.length, 9); assert.equal(results[0].localPath, "contentChange.txt"); assert.equal(results[0].type, ConflictType.CONTENT); assert.equal(results[1].localPath, "addConflict.txt"); @@ -115,14 +136,16 @@ describe("Tfvc-FindConflictsCommand", function() { assert.equal(results[2].type, ConflictType.RENAME); assert.equal(results[3].localPath, "nameAndContentChange.txt"); assert.equal(results[3].type, ConflictType.NAME_AND_CONTENT); - assert.equal(results[4].localPath, "contentChange2.txt"); - assert.equal(results[4].type, ConflictType.CONTENT); - assert.equal(results[5].localPath, "deleted.txt"); - assert.equal(results[5].type, ConflictType.DELETE); - assert.equal(results[6].localPath, "branchEdit.txt"); - assert.equal(results[6].type, ConflictType.MERGE); - assert.equal(results[7].localPath, "branchDelete.txt"); - assert.equal(results[7].type, ConflictType.DELETE_TARGET); + assert.equal(results[4].localPath, "anotherNameAndContentChange.txt"); + assert.equal(results[4].type, ConflictType.NAME_AND_CONTENT); + assert.equal(results[5].localPath, "contentChange2.txt"); + assert.equal(results[5].type, ConflictType.CONTENT); + assert.equal(results[6].localPath, "deleted.txt"); + assert.equal(results[6].type, ConflictType.DELETE); + assert.equal(results[7].localPath, "branchEdit.txt"); + assert.equal(results[7].type, ConflictType.MERGE); + assert.equal(results[8].localPath, "branchDelete.txt"); + assert.equal(results[8].type, ConflictType.DELETE_TARGET); }); it("should verify parse output - errors - exit code 100", async function() { @@ -143,4 +166,76 @@ describe("Tfvc-FindConflictsCommand", function() { assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); + + it("should verify parse Exe output - no output", async function() { + let localPath: string = "/usr/alias/repo1"; + let cmd: FindConflicts = new FindConflicts(undefined, localPath); + let executionResult: IExecutionResult = { + exitCode: 0, + stdout: undefined, + stderr: undefined + }; + + let results: IConflict[] = await cmd.ParseExeOutput(executionResult); + assert.equal(results.length, 0); + }); + + it("should verify parse Exe output - one of each type", async function() { + let localPath: string = "/usr/alias/repo1"; + let cmd: FindConflicts = new FindConflicts(undefined, localPath); + let executionResult: IExecutionResult = { + exitCode: 0, + stdout: "", + stderr: "contentChange.txt: The item content has changed\n" + + "addConflict.txt: Another item with the same name exists on the server\n" + + "nameChange.txt: The item name has changed\n" + + "nameAndContentChange.txt: The item name and content have changed\n" + + "anotherNameAndContentChange.txt: You have a conflicting pending change\n" + + "contentChange2.txt: The item content has changed\n" + + "deleted.txt: The item has already been deleted\n" + + "branchEdit.txt: The source and target both have changes\n" + + "branchDelete.txt: The item has been deleted in the target branch" + }; + + let results: IConflict[] = await cmd.ParseExeOutput(executionResult); + assert.equal(results.length, 9); + assert.equal(results[0].localPath, "contentChange.txt"); + assert.equal(results[0].type, ConflictType.CONTENT); + assert.equal(results[1].localPath, "addConflict.txt"); + assert.equal(results[1].type, ConflictType.CONTENT); + assert.equal(results[2].localPath, "nameChange.txt"); + assert.equal(results[2].type, ConflictType.RENAME); + assert.equal(results[3].localPath, "nameAndContentChange.txt"); + assert.equal(results[3].type, ConflictType.NAME_AND_CONTENT); + assert.equal(results[4].localPath, "anotherNameAndContentChange.txt"); + assert.equal(results[4].type, ConflictType.NAME_AND_CONTENT); + assert.equal(results[5].localPath, "contentChange2.txt"); + assert.equal(results[5].type, ConflictType.CONTENT); + assert.equal(results[6].localPath, "deleted.txt"); + assert.equal(results[6].type, ConflictType.DELETE); + assert.equal(results[7].localPath, "branchEdit.txt"); + assert.equal(results[7].type, ConflictType.MERGE); + assert.equal(results[8].localPath, "branchDelete.txt"); + assert.equal(results[8].type, ConflictType.DELETE_TARGET); + }); + + it("should verify parse Exe output - errors - exit code 100", async function() { + let localPath: string = "/usr/alias/repo 1"; + let cmd: FindConflicts = new FindConflicts(undefined, localPath); + let executionResult: IExecutionResult = { + exitCode: 100, + stdout: "Something bad this way comes.", + stderr: undefined + }; + + try { + await cmd.ParseExeOutput(executionResult); + } catch (err) { + assert.equal(err.exitCode, 100); + assert.equal(err.tfvcCommand, "resolve"); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); + } + }); + }); diff --git a/test/tfvc/commands/resolveconflicts.test.ts b/test/tfvc/commands/resolveconflicts.test.ts index a13661d186..f7756a5a5d 100644 --- a/test/tfvc/commands/resolveconflicts.test.ts +++ b/test/tfvc/commands/resolveconflicts.test.ts @@ -155,8 +155,8 @@ describe("Tfvc-ResolveConflictsCommand", function() { } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "resolve"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); @@ -209,8 +209,8 @@ describe("Tfvc-ResolveConflictsCommand", function() { } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "resolve"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); }); diff --git a/test/tfvc/commands/sync.test.ts b/test/tfvc/commands/sync.test.ts index 15e6bfb4ff..06f3248d05 100644 --- a/test/tfvc/commands/sync.test.ts +++ b/test/tfvc/commands/sync.test.ts @@ -310,8 +310,8 @@ describe("Tfvc-SyncCommand", function() { } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "get"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); @@ -519,8 +519,8 @@ describe("Tfvc-SyncCommand", function() { } catch (err) { assert.equal(err.exitCode, 100); assert.equal(err.tfvcCommand, "get"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); diff --git a/test/tfvc/commands/undo.test.ts b/test/tfvc/commands/undo.test.ts index 79046b31be..6a5059abe2 100644 --- a/test/tfvc/commands/undo.test.ts +++ b/test/tfvc/commands/undo.test.ts @@ -256,8 +256,8 @@ describe("Tfvc-UndoCommand", function() { } catch (err) { assert.equal(err.exitCode, 42); assert.equal(err.tfvcCommand, "undo"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); @@ -418,8 +418,8 @@ describe("Tfvc-UndoCommand", function() { } catch (err) { assert.equal(err.exitCode, 42); assert.equal(err.tfvcCommand, "undo"); - assert.equal(err.message.indexOf(Strings.TfExecFailedError), 0); - assert.equal(err.stdout.indexOf("Something bad this way comes."), 0); + assert.isTrue(err.message.startsWith(Strings.TfExecFailedError)); + assert.isTrue(err.stdout.startsWith("Something bad this way comes.")); } }); });