Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Boost FindConflicts code coverage #128

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tfvc/commands/findconflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class FindConflicts implements ITfvcCommand<IConflict[]> {
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IConflict[]> {
return this.ParseOutput(executionResult);
return await this.ParseOutput(executionResult);
}

}
24 changes: 12 additions & 12 deletions test/tfvc/commands/commandhelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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);
}
});
Expand All @@ -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");
}
});
Expand Down
113 changes: 104 additions & 9 deletions test/tfvc/commands/findconflicts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,40 @@ 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);

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);

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);
Expand All @@ -99,14 +119,15 @@ 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" +
"branchDelete.txt: The item has been deleted in the target branch"
};

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");
Expand All @@ -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() {
Expand All @@ -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."));
}
});

});
8 changes: 4 additions & 4 deletions test/tfvc/commands/resolveconflicts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
});

Expand Down Expand Up @@ -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."));
}
});
});
8 changes: 4 additions & 4 deletions test/tfvc/commands/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
});

Expand Down Expand Up @@ -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."));
}
});

Expand Down
8 changes: 4 additions & 4 deletions test/tfvc/commands/undo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
}
});

Expand Down Expand Up @@ -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."));
}
});
});