Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair Functional Tests: test for confirm on and off #335

Merged
merged 1 commit into from
Oct 8, 2018
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
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