Skip to content

Commit

Permalink
Repair Functional Tests: test for confirm on and off
Browse files Browse the repository at this point in the history
Enrich existing tests to include confirm off
  • Loading branch information
jeschu1 committed Oct 4, 2018
1 parent bd66019 commit 46f9bc5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class RepairTests : TestsWithEnlistmentPerTestCase
public void NoFixesNeeded()
{
this.Enlistment.UnmountGVFS();

this.Enlistment.Repair();
this.Enlistment.Repair(confirm: false);
this.Enlistment.Repair(confirm: true);
}

[TestCase]
Expand All @@ -28,12 +28,11 @@ public void FixesCorruptHeadSha()

string headFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "HEAD");
File.WriteAllText(headFilePath, "0000");

this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when HEAD is corrupt");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -43,12 +42,11 @@ public void FixesCorruptHeadSymRef()

string headFilePath = Path.Combine(this.Enlistment.RepoRoot, ".git", "HEAD");
File.WriteAllText(headFilePath, "ref: refs");

this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when HEAD is corrupt");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -58,12 +56,11 @@ public void FixesMissingGitIndex()

string gitIndexPath = Path.Combine(this.Enlistment.RepoRoot, ".git", "index");
File.Delete(gitIndexPath);

this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when git index is missing");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -84,9 +81,9 @@ public void FixesGitIndexCorruptedWithBadData()
this.Enlistment.TryMountGVFS(out output).ShouldEqual(false, "GVFS shouldn't mount when index is corrupt");
output.ShouldContain("Index validation failed");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -108,9 +105,9 @@ public void FixesGitIndexContainingAllNulls()
this.Enlistment.TryMountGVFS(out output).ShouldEqual(false, "GVFS shouldn't mount when index is corrupt");
output.ShouldContain("Index validation failed");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -135,9 +132,9 @@ public void FixesGitIndexCorruptedByTruncation()
this.Enlistment.TryMountGVFS(out output).ShouldEqual(false, "GVFS shouldn't mount when index is corrupt");
output.ShouldContain("Index validation failed");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.MountGVFS();
this.RepairWithConfirmShouldFix();
}

[TestCase]
Expand All @@ -150,11 +147,11 @@ public void FixesCorruptGitConfig()

this.Enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when git config is missing");

this.Enlistment.Repair();
this.RepairWithoutConfirmShouldNotFix();

this.Enlistment.Repair(confirm: true);
ProcessResult result = GitProcess.InvokeProcess(this.Enlistment.RepoRoot, "remote add origin " + this.Enlistment.RepoUrl);
result.ExitCode.ShouldEqual(0, result.Errors);

result.ExitCode.ShouldEqual(0, result.Errors);
this.Enlistment.MountGVFS();
}

Expand All @@ -170,5 +167,17 @@ private void CreateCorruptIndexAndRename(string indexPath, Action<FileStream, Fi
File.Delete(indexPath);
File.Move(tempIndexPath, indexPath);
}

private void RepairWithConfirmShouldFix()
{
this.Enlistment.Repair(confirm: true);
this.Enlistment.MountGVFS();
}

private void RepairWithoutConfirmShouldNotFix()
{
this.Enlistment.Repair(confirm: false);
this.Enlistment.TryMountGVFS().ShouldEqual(false, "Repair without confirm should not fix the enlistment");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public void RepairFixesCorruptBlobSizesDatabase()
enlistment.UnmountGVFS();

// Repair on a healthy enlistment should succeed
enlistment.Repair();
enlistment.Repair(confirm: true);

string blobSizesRoot = GVFSHelpers.GetPersistedBlobSizesRoot(enlistment.DotGVFSRoot).ShouldNotBeNull();
string blobSizesDbPath = Path.Combine(blobSizesRoot, "BlobSizes.sql");
blobSizesDbPath.ShouldBeAFile(this.fileSystem);
this.fileSystem.WriteAllText(blobSizesDbPath, "0000");

enlistment.TryMountGVFS().ShouldEqual(false, "GVFS shouldn't mount when blob size db is corrupt");
enlistment.Repair();
enlistment.Repair(confirm: true);
enlistment.MountGVFS();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ public string Prefetch(string args, bool failOnError = true)
return this.gvfsProcess.Prefetch(args, failOnError);
}

public void Repair()
public void Repair(bool confirm)
{
this.gvfsProcess.Repair();
this.gvfsProcess.Repair(confirm);
}

public string Diagnose()
Expand Down
5 changes: 3 additions & 2 deletions GVFS/GVFS.FunctionalTests/Tools/GVFSProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public string Prefetch(string args, bool failOnError)
return this.CallGVFS("prefetch \"" + this.enlistmentRoot + "\" " + args, failOnError);
}

public void Repair()
public void Repair(bool confirm)
{
string confirmArg = confirm ? "--confirm " : string.Empty;
this.CallGVFS(
"repair --confirm \"" + this.enlistmentRoot + "\"",
"repair " + confirmArg + "\"" + this.enlistmentRoot + "\"",
failOnError: true);
}

Expand Down

0 comments on commit 46f9bc5

Please sign in to comment.