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

Adding tests for several commands #127

Merged
merged 3 commits 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/resolveconflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ export class ResolveConflicts implements ITfvcCommand<IConflict[]> {
}

public async ParseExeOutput(executionResult: IExecutionResult): Promise<IConflict[]> {
return this.ParseOutput(executionResult);
return await this.ParseOutput(executionResult);
}
}
4 changes: 2 additions & 2 deletions src/tfvc/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Sync implements ITfvcCommand<ISyncResults> {
}

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

private getItemResults(stdout: string): ISyncItemResult[] {
Expand Down Expand Up @@ -177,7 +177,7 @@ export class Sync implements ITfvcCommand<ISyncResults> {
index = line.indexOf("cannot be deleted");
if (index >= 0) {
newResult = {
syncType: SyncType.Error,
syncType: SyncType.Warning,
itemPath: CommandHelper.GetFilePath(folderPath, line.slice(0, index).trim()),
message: line.trim()
};
Expand Down
2 changes: 1 addition & 1 deletion src/tfvc/commands/undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Undo implements ITfvcCommand<string[]> {
}

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

//line could be 'Undoing edit: file1.txt', 'Undoing add: file1.txt'
Expand Down
81 changes: 81 additions & 0 deletions test/tfvc/commands/resolveconflicts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ describe("Tfvc-ResolveConflictsCommand", function() {
assert.deepEqual(cmd.GetOptions(), {});
});

it("should verify GetExeOptions", function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
assert.deepEqual(cmd.GetExeOptions(), {});
});

it("should verify arguments", function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
Expand All @@ -83,6 +89,27 @@ describe("Tfvc-ResolveConflictsCommand", function() {
assert.equal(cmd.GetArguments().GetArgumentsForDisplay(), "resolve -noprompt -collection:" + collectionUrl + " ******** " + localPaths[0] + " -auto:TakeTheirs");
});

it("should verify GetExeArguments", function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);

assert.equal(cmd.GetExeArguments().GetArgumentsForDisplay(), "resolve -noprompt " + localPaths[0] + " -auto:KeepYours");
});

it("should verify GetExeArguments with context", function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(context, localPaths, AutoResolveType.KeepYours);

assert.equal(cmd.GetExeArguments().GetArgumentsForDisplay(), "resolve -noprompt ******** " + localPaths[0] + " -auto:KeepYours");
});

it("should verify GetExeArguments with TakeTheirs", function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(context, localPaths, AutoResolveType.TakeTheirs);

assert.equal(cmd.GetExeArguments().GetArgumentsForDisplay(), "resolve -noprompt ******** " + localPaths[0] + " -auto:TakeTheirs");
});

it("should verify parse output - no output", async function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
Expand Down Expand Up @@ -132,4 +159,58 @@ describe("Tfvc-ResolveConflictsCommand", function() {
assert.equal(err.stdout.indexOf("Something bad this way comes."), 0);
}
});

/***********************************************************************************************
* The methods below are duplicates of the parse output methods but call the parseExeOutput.
***********************************************************************************************/

it("should verify parse EXE output - no output", async function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
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 - no errors", async function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt", "/usr/alias/repo1/file2.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
let executionResult: IExecutionResult = {
exitCode: 0,
stdout: "Resolved /usr/alias/repo1/file.txt as KeepYours\n" +
"Resolved /usr/alias/repo1/file2.txt as KeepYours",
stderr: undefined
};

let results: IConflict[] = await cmd.ParseExeOutput(executionResult);
assert.equal(results.length, 2);
assert.equal(results[0].localPath, "/usr/alias/repo1/file.txt");
assert.equal(results[0].type, ConflictType.RESOLVED);
assert.equal(results[1].localPath, "/usr/alias/repo1/file2.txt");
assert.equal(results[1].type, ConflictType.RESOLVED);
});

it("should verify parse EXE output - errors - exit code 100", async function() {
let localPaths: string[] = ["/usr/alias/repo1/file.txt"];
let cmd: ResolveConflicts = new ResolveConflicts(undefined, localPaths, AutoResolveType.KeepYours);
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.equal(err.message.indexOf(Strings.TfExecFailedError), 0);
assert.equal(err.stdout.indexOf("Something bad this way comes."), 0);
}
});
});
Loading