Skip to content

Commit

Permalink
Make checks on the modified paths be more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Willford committed Oct 1, 2018
1 parent 8eddf8b commit 558b7e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ public void CaseOnlyRenameOfNewFolderKeepsModifiedPathsEntries()
this.fileSystem.CreateEmptyFile(Path.Combine(this.Enlistment.RepoRoot, "Folder", "testfile"));
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A Folder/");
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "Folder/");

this.fileSystem.RenameDirectory(this.Enlistment.RepoRoot, "Folder", "folder");
this.Enlistment.WaitForBackgroundOperations().ShouldEqual(true, "Background operations failed to complete.");

GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/");
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "A folder/testfile");
GVFSHelpers.ModifiedPathsShouldContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "folder/");
GVFSHelpers.ModifiedPathsShouldNotContain(this.fileSystem, this.Enlistment.DotGVFSRoot, "folder/testfile");
}

[TestCase, Order(7)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void DeletedTempFileIsRemovedFromModifiedFiles(FileSystemRunner fileSyste
tempFile.ShouldNotExistOnDisk(fileSystem);

this.Enlistment.UnmountGVFS();
this.ValidateModifiedPathsDoNotContain(fileSystem, "temp.txt");
GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "temp.txt");
}

[TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)]
Expand All @@ -64,7 +64,7 @@ public void DeletedTempFolderIsRemovedFromModifiedFiles(FileSystemRunner fileSys
tempFolder.ShouldNotExistOnDisk(fileSystem);

this.Enlistment.UnmountGVFS();
this.ValidateModifiedPathsDoNotContain(fileSystem, "Temp/");
GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "Temp/");
}

[TestCaseSource(typeof(FileSystemRunner), FileSystemRunner.TestRunners)]
Expand All @@ -79,7 +79,7 @@ public void DeletedTempFolderDeletesFilesFromModifiedFiles(FileSystemRunner file
tempFile2.ShouldNotExistOnDisk(fileSystem);

this.Enlistment.UnmountGVFS();
this.ValidateModifiedPathsDoNotContain(fileSystem, "Temp/", "Temp/temp1.txt", "Temp/temp2.txt");
GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, "Temp/", "Temp/temp1.txt", "Temp/temp2.txt");
}

[Category(Categories.MacTODO.M2)]
Expand Down Expand Up @@ -219,11 +219,5 @@ private string CreateFile(FileSystemRunner fileSystem, string relativePath)
tempFile.ShouldBeAFile(fileSystem);
return tempFile;
}

private void ValidateModifiedPathsDoNotContain(FileSystemRunner fileSystem, params string[] paths)
{
GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, paths.Select(x => $"A {x}" + Environment.NewLine).ToArray());
GVFSHelpers.ModifiedPathsShouldNotContain(fileSystem, this.Enlistment.DotGVFSRoot, paths.Select(x => $"D {x}" + Environment.NewLine).ToArray());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -980,15 +980,17 @@ public void EditFileNeedingUtf8Encoding()
{
this.ValidateGitCommand("checkout -b tests/functional/EditFileNeedingUtf8Encoding");
this.ValidateGitCommand("status");

string virtualFile = Path.Combine(this.Enlistment.RepoRoot, EncodingFileFolder, EncodingFilename);
string controlFile = Path.Combine(this.ControlGitRepo.RootPath, EncodingFileFolder, EncodingFilename);
string relativeGitPath = EncodingFileFolder + "/" + EncodingFilename;

string contents = virtualFile.ShouldBeAFile(this.FileSystem).WithContents();
string expectedContents = controlFile.ShouldBeAFile(this.FileSystem).WithContents();
contents.ShouldEqual(expectedContents);

// Confirm that the entry is not in the the modified paths database
GVFSHelpers.ModifiedPathsShouldNotContain(this.FileSystem, this.Enlistment.DotGVFSRoot, EncodingFilename);
GVFSHelpers.ModifiedPathsShouldNotContain(this.FileSystem, this.Enlistment.DotGVFSRoot, relativeGitPath);
this.ValidateGitCommand("status");

this.AppendAllText(ContentWhenEditingFile, virtualFile);
Expand All @@ -997,7 +999,7 @@ public void EditFileNeedingUtf8Encoding()
this.ValidateGitCommand("status");

// Confirm that the entry was added to the modified paths database
GVFSHelpers.ModifiedPathsShouldContain(this.FileSystem, this.Enlistment.DotGVFSRoot, EncodingFilename);
GVFSHelpers.ModifiedPathsShouldContain(this.FileSystem, this.Enlistment.DotGVFSRoot, relativeGitPath);
}

[TestCase]
Expand Down
25 changes: 21 additions & 4 deletions GVFS/GVFS.FunctionalTests/Tools/GVFSHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using Microsoft.Data.Sqlite;
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace GVFS.FunctionalTests.Tools
{
Expand All @@ -19,6 +19,9 @@ public static class GVFSHelpers
public static readonly string PlaceholderListFile = Path.Combine("databases", "PlaceholderList.dat");
public static readonly string RepoMetadataName = Path.Combine("databases", "RepoMetadata.dat");

private const string ModifedPathsLineAddPrefix = "A ";
private const string ModifedPathsLineDeletePrefix = "D ";

private const string DiskLayoutMajorVersionKey = "DiskLayoutVersion";
private const string DiskLayoutMinorVersionKey = "DiskLayoutMinorVersion";
private const string LocalCacheRootKey = "LocalCacheRoot";
Expand Down Expand Up @@ -111,15 +114,29 @@ public static void ModifiedPathsShouldContain(FileSystemRunner fileSystem, strin
{
string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);
modifiedPathsDatabase.ShouldBeAFile(fileSystem);
GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldContain(
gitPaths.Select(path => path + ModifiedPathsNewLine).ToArray());
string modifedPathsContents = GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase);
string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None);
foreach (string gitPath in gitPaths)
{
modifedPathLines.ShouldContain(path => path.Equals(ModifedPathsLineAddPrefix + gitPath));
}
}

public static void ModifiedPathsShouldNotContain(FileSystemRunner fileSystem, string dotGVFSRoot, params string[] gitPaths)
{
string modifiedPathsDatabase = Path.Combine(dotGVFSRoot, TestConstants.Databases.ModifiedPaths);
modifiedPathsDatabase.ShouldBeAFile(fileSystem);
GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase).ShouldNotContain(ignoreCase: true, unexpectedSubstrings: gitPaths);
string modifedPathsContents = GVFSHelpers.ReadAllTextFromWriteLockedFile(modifiedPathsDatabase);
string[] modifedPathLines = modifedPathsContents.Split(new[] { ModifiedPathsNewLine }, StringSplitOptions.None);
foreach (string gitPath in gitPaths)
{
modifedPathLines.ShouldNotContain(
path =>
{
return path.Equals(ModifedPathsLineAddPrefix + gitPath, StringComparison.OrdinalIgnoreCase) ||
path.Equals(ModifedPathsLineDeletePrefix + gitPath, StringComparison.OrdinalIgnoreCase);
});
}
}

private static byte[] StringToShaBytes(string sha)
Expand Down

0 comments on commit 558b7e2

Please sign in to comment.