Skip to content

Commit

Permalink
Move LooseObjectStepTests to EnlistmentPerFixture
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Aug 19, 2019
1 parent 8cf618d commit c1c0eb0
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
using Scalar.FunctionalTests.FileSystemRunners;
using Scalar.FunctionalTests.Tools;
using Scalar.Tests.Should;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace Scalar.FunctionalTests.Tests.EnlistmentPerTestCase
namespace Scalar.FunctionalTests.Tests.EnlistmentPerFixture
{
[TestFixture]
public class LooseObjectStepTests : TestsWithEnlistmentPerTestCase
public class LooseObjectStepTests : TestsWithEnlistmentPerFixture
{
private const string TempPackFolder = "tempPacks";
private FileSystemRunner fileSystem;

// Set forcePerRepoObjectCache to true to avoid any of the tests inadvertently corrupting
// the cache
public LooseObjectStepTests()
: base(forcePerRepoObjectCache: true)
: base(forcePerRepoObjectCache: false)
{
this.fileSystem = new SystemIORunner();
}
Expand All @@ -28,6 +29,7 @@ public LooseObjectStepTests()
private string TempPackRoot => Path.Combine(this.PackRoot, TempPackFolder);

[TestCase]
[Order(3)]
public void RemoveLooseObjectsInPackFiles()
{
this.ClearAllObjects();
Expand All @@ -47,6 +49,7 @@ public void RemoveLooseObjectsInPackFiles()
}

[TestCase]
[Order(4)]
public void PutLooseObjectsInPackFiles()
{
this.ClearAllObjects();
Expand All @@ -70,6 +73,7 @@ public void PutLooseObjectsInPackFiles()
}

[TestCase]
[Order(2)]
public void NoLooseObjectsDoesNothing()
{
this.DeleteFiles(this.GetLooseObjectFiles());
Expand All @@ -83,6 +87,7 @@ public void NoLooseObjectsDoesNothing()
}

[TestCase]
[Order(1)]
public void CorruptLooseObjectIsDeleted()
{
this.ClearAllObjects();
Expand Down Expand Up @@ -125,17 +130,24 @@ public void CorruptLooseObjectIsDeleted()

private void ClearAllObjects()
{
Console.Error.WriteLine("ClearAllObjects: start");

this.Enlistment.UnmountScalar();

Console.Error.WriteLine("ClearAllObjects: middle");

// Delete/Move any starting loose objects and packfiles
this.DeleteFiles(this.GetLooseObjectFiles());
this.MovePackFilesToTemp();
this.GetLooseObjectFiles().Count.ShouldEqual(0, "incorrect number of loose objects after setup");
this.CountPackFiles().ShouldEqual(0, "incorrect number of packs after setup");
Console.Error.WriteLine("ClearAllObjects: end");
}

private List<string> GetLooseObjectFiles()
{
Console.Error.WriteLine("GetLooseObjectFiles: start");

List<string> looseObjectFiles = new List<string>();
foreach (string directory in Directory.GetDirectories(this.GitObjectRoot))
{
Expand All @@ -152,6 +164,8 @@ private List<string> GetLooseObjectFiles()

private void DeleteFiles(List<string> filePaths)
{
Console.Error.WriteLine("DeleteFiles: start");

foreach (string filePath in filePaths)
{
File.Delete(filePath);
Expand All @@ -165,6 +179,8 @@ private int CountPackFiles()

private void MovePackFilesToTemp()
{
Console.Error.WriteLine("MovePackFilesToTemp: start");

string[] files = Directory.GetFiles(this.PackRoot);
foreach (string file in files)
{
Expand All @@ -176,6 +192,8 @@ private void MovePackFilesToTemp()

private void ExpandOneTempPack(bool copyPackBackToPackDirectory)
{
Console.Error.WriteLine("ExpandOneTempPack: start");

// Find all pack files
string[] packFiles = Directory.GetFiles(this.TempPackRoot, "pack-*.pack");
Assert.Greater(packFiles.Length, 0);
Expand All @@ -189,6 +207,8 @@ private void ExpandOneTempPack(bool copyPackBackToPackDirectory)
// Note this won't work if the object exists in a pack file which is why we had to move them
using (FileStream packFileStream = File.OpenRead(packFile))
{
Console.Error.WriteLine("ExpandOneTempPack: OpenRead to InvokePorcess");

string output = GitProcess.InvokeProcess(
this.Enlistment.RepoRoot,
"unpack-objects",
Expand All @@ -198,6 +218,8 @@ private void ExpandOneTempPack(bool copyPackBackToPackDirectory)

if (copyPackBackToPackDirectory)
{
Console.Error.WriteLine("ExpandOneTempPack: copying to pack dir");

// Copy the pack file back to packs
string packFileName = Path.GetFileName(packFile);
File.Copy(packFile, Path.Combine(this.PackRoot, packFileName));
Expand Down

0 comments on commit c1c0eb0

Please sign in to comment.