Skip to content

Commit

Permalink
FunctionalTests: drop negative runner methods
Browse files Browse the repository at this point in the history
We can prune the various negative "should fail" and "should not"
methods from the FileSystemRunner classes as these are no longer
utilized by any tests.

These methods were previously used by the BasicFileSystemTests and
MoveRenameFolderTests, which were removed in commit
d748084.
  • Loading branch information
chrisd8088 committed Oct 4, 2020
1 parent 7a86016 commit 46598af
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 287 deletions.
61 changes: 0 additions & 61 deletions Scalar.FunctionalTests/FileSystemRunners/BashRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,6 @@ public override string MoveFile(string sourcePath, string targetPath)
return this.RunProcess(string.Format("-c \"mv '{0}' '{1}'\"", sourceBashPath, targetBashPath));
}

public override void MoveFileShouldFail(string sourcePath, string targetPath)
{
// BashRunner does nothing special when a failure is expected, so just confirm source file is still present
this.MoveFile(sourcePath, targetPath);
this.FileExists(sourcePath).ShouldBeTrue($"{sourcePath} does not exist when it should");
}

public override void MoveFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContainOneOf(fileNotFoundMessages);
}

public override string ReplaceFile(string sourcePath, string targetPath)
{
string sourceBashPath = this.ConvertWinPathToBashPath(sourcePath);
Expand Down Expand Up @@ -194,12 +182,6 @@ public override void WriteAllText(string path, string contents)
this.RunProcess(string.Format("-c \"echo \\\"{0}\\\" > '{1}'\"", contents, bashPath));
}

public override void WriteAllTextShouldFail<ExceptionType>(string path, string contents)
{
// BashRunner does nothing special when a failure is expected
this.WriteAllText(path, contents);
}

public override bool DirectoryExists(string path)
{
return this.FileExistsOnDisk(path, FileType.Directory);
Expand All @@ -215,16 +197,6 @@ public override void RenameDirectory(string workingDirectory, string source, str
this.MoveDirectory(Path.Combine(workingDirectory, source), Path.Combine(workingDirectory, target));
}

public override void MoveDirectory_RequestShouldNotBeSupported(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContain(moveDirectoryNotSupportedMessage);
}

public override void MoveDirectory_TargetShouldBeInvalid(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContainOneOf(invalidMovePathMessages);
}

public override void CreateDirectory(string path)
{
string bashPath = this.ConvertWinPathToBashPath(path);
Expand All @@ -246,34 +218,6 @@ public override string EnumerateDirectory(string path)
return this.RunProcess(string.Format("-c \"ls '{0}'\"", bashPath));
}

public override void ReplaceFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.ReplaceFile(sourcePath, targetPath).ShouldContainOneOf(fileNotFoundMessages);
}

public override void DeleteFile_FileShouldNotBeFound(string path)
{
this.DeleteFile(path).ShouldContainOneOf(fileNotFoundMessages);
}

public override void DeleteFile_AccessShouldBeDenied(string path)
{
// bash does not report any error messages when access is denied, so just confirm the file still exists
this.DeleteFile(path);
this.FileExists(path).ShouldBeTrue($"{path} does not exist when it should");
}

public override void ReadAllText_FileShouldNotBeFound(string path)
{
this.ReadAllText(path).ShouldContainOneOf(fileNotFoundMessages);
}

public override void DeleteDirectory_DirectoryShouldNotBeFound(string path)
{
// Delete directory silently succeeds when deleting a non-existent path
this.DeleteDirectory(path);
}

public override void ChangeMode(string path, ushort mode)
{
string octalMode = Convert.ToString(mode, 8);
Expand All @@ -282,11 +226,6 @@ public override void ChangeMode(string path, ushort mode)
this.RunProcess(command);
}

public override void DeleteDirectory_ShouldBeBlockedByProcess(string path)
{
Assert.Fail("Unlike the other runners, bash.exe does not check folder handle before recusively deleting");
}

public override long FileSize(string path)
{
string bashPath = this.ConvertWinPathToBashPath(path);
Expand Down
59 changes: 0 additions & 59 deletions Scalar.FunctionalTests/FileSystemRunners/CmdRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ public override string MoveFile(string sourcePath, string targetPath)
return this.RunProcess(string.Format("/C move \"{0}\" \"{1}\"", sourcePath, targetPath));
}

public override void MoveFileShouldFail(string sourcePath, string targetPath)
{
// CmdRunner does nothing special when a failure is expected
this.MoveFile(sourcePath, targetPath);
}

public override void MoveFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContainOneOf(missingFileErrorMessages);
}

public override string ReplaceFile(string sourcePath, string targetPath)
{
return this.RunProcess(string.Format("/C move /Y \"{0}\" \"{1}\"", sourcePath, targetPath));
Expand Down Expand Up @@ -128,12 +117,6 @@ public override void WriteAllText(string path, string contents)
this.RunProcess(string.Format("/C echo|set /p =\"{0}\" > {1}", contents, path));
}

public override void WriteAllTextShouldFail<ExceptionType>(string path, string contents)
{
// CmdRunner does nothing special when a failure is expected
this.WriteAllText(path, contents);
}

public override bool DirectoryExists(string path)
{
string parentDirectory = Path.GetDirectoryName(path);
Expand Down Expand Up @@ -178,53 +161,11 @@ public override void RenameDirectory(string workingDirectory, string source, str
this.RunProcess(string.Format("/C ren \"{0}\" \"{1}\"", source, target), workingDirectory);
}

public override void MoveDirectory_RequestShouldNotBeSupported(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContain(moveDirectoryFailureMessage);
}

public override void MoveDirectory_TargetShouldBeInvalid(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContain(moveDirectoryFailureMessage);
}

public string RunCommand(string command)
{
return this.RunProcess(string.Format("/C {0}", command));
}

public override void ReplaceFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.ReplaceFile(sourcePath, targetPath).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteFile_FileShouldNotBeFound(string path)
{
this.DeleteFile(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteFile_AccessShouldBeDenied(string path)
{
// CMD does not report any error messages when access is denied, so just confirm the file still exists
this.DeleteFile(path);
this.FileExists(path).ShouldEqual(true);
}

public override void ReadAllText_FileShouldNotBeFound(string path)
{
this.ReadAllText(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteDirectory_DirectoryShouldNotBeFound(string path)
{
this.DeleteDirectory(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteDirectory_ShouldBeBlockedByProcess(string path)
{
this.DeleteDirectory(path).ShouldContain(fileUsedByAnotherProcessMessage);
}

public override void ChangeMode(string path, ushort mode)
{
throw new NotSupportedException();
Expand Down
27 changes: 0 additions & 27 deletions Scalar.FunctionalTests/FileSystemRunners/FileSystemRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,9 @@ public static FileSystemRunner DefaultRunner
public abstract bool FileExists(string path);
public abstract string MoveFile(string sourcePath, string targetPath);

/// <summary>
/// Attempt to move the specified file to the specifed target path. By calling this method the caller is
/// indicating that they expect the move to fail. However, the caller is responsible for verifying that
/// the move failed.
/// </summary>
/// <param name="sourcePath">Path to existing file</param>
/// <param name="targetPath">Path to target file (target of the move)</param>
public abstract void MoveFileShouldFail(string sourcePath, string targetPath);
public abstract void MoveFile_FileShouldNotBeFound(string sourcePath, string targetPath);
public abstract string ReplaceFile(string sourcePath, string targetPath);
public abstract void ReplaceFile_FileShouldNotBeFound(string sourcePath, string targetPath);
public abstract string DeleteFile(string path);
public abstract void DeleteFile_FileShouldNotBeFound(string path);
public abstract void DeleteFile_AccessShouldBeDenied(string path);
public abstract string ReadAllText(string path);
public abstract void ReadAllText_FileShouldNotBeFound(string path);

public abstract void CreateEmptyFile(string path);
public abstract void CreateHardLink(string newLinkFilePath, string existingFilePath);
Expand All @@ -86,22 +73,10 @@ public static FileSystemRunner DefaultRunner
/// <param name="contents">File contents</param>
public abstract void AppendAllText(string path, string contents);

/// <summary>
/// Attempt to write the specified contents to the specified file. By calling this method the caller is
/// indicating that they expect the write to fail. However, the caller is responsible for verifying that
/// the write failed.
/// </summary>
/// <typeparam name="ExceptionType">Expected type of exception to be thrown</typeparam>
/// <param name="path">Path to file</param>
/// <param name="contents">File contents</param>
public abstract void WriteAllTextShouldFail<ExceptionType>(string path, string contents) where ExceptionType : Exception;

// Directory methods
public abstract bool DirectoryExists(string path);
public abstract void MoveDirectory(string sourcePath, string targetPath);
public abstract void RenameDirectory(string workingDirectory, string source, string target);
public abstract void MoveDirectory_RequestShouldNotBeSupported(string sourcePath, string targetPath);
public abstract void MoveDirectory_TargetShouldBeInvalid(string sourcePath, string targetPath);
public abstract void CreateDirectory(string path);
public abstract string EnumerateDirectory(string path);
public abstract long FileSize(string path);
Expand All @@ -110,7 +85,5 @@ public static FileSystemRunner DefaultRunner
/// A recursive delete of a directory
/// </summary>
public abstract string DeleteDirectory(string path);
public abstract void DeleteDirectory_DirectoryShouldNotBeFound(string path);
public abstract void DeleteDirectory_ShouldBeBlockedByProcess(string path);
}
}
58 changes: 0 additions & 58 deletions Scalar.FunctionalTests/FileSystemRunners/PowerShellRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ public override string MoveFile(string sourcePath, string targetPath)
return this.RunProcess(string.Format("-Command \"& {{ Move-Item {0} {1} -force}}\"", sourcePath, targetPath));
}

public override void MoveFileShouldFail(string sourcePath, string targetPath)
{
// PowerShellRunner does nothing special when a failure is expected
this.MoveFile(sourcePath, targetPath);
}

public override void MoveFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContainOneOf(missingFileErrorMessages);
}

public override string ReplaceFile(string sourcePath, string targetPath)
{
return this.RunProcess(string.Format("-Command \"& {{ Move-Item {0} {1} -force }}\"", sourcePath, targetPath));
Expand Down Expand Up @@ -116,12 +105,6 @@ public override void WriteAllText(string path, string contents)
this.RunProcess(string.Format("-Command \"&{{ Out-File -FilePath {0} -InputObject '{1}' -Encoding ascii -NoNewline}}\"", path, contents));
}

public override void WriteAllTextShouldFail<ExceptionType>(string path, string contents)
{
// PowerShellRunner does nothing special when a failure is expected
this.WriteAllText(path, contents);
}

public override bool DirectoryExists(string path)
{
string command = string.Format("-Command \"&{{ Test-Path {0} -PathType Container }}\"", path);
Expand All @@ -145,16 +128,6 @@ public override void RenameDirectory(string workingDirectory, string source, str
this.RunProcess(string.Format("-Command \"& {{ Rename-Item -Path {0} -NewName {1} -force }}\"", Path.Combine(workingDirectory, source), target));
}

public override void MoveDirectory_RequestShouldNotBeSupported(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContain(moveDirectoryNotSupportedMessage);
}

public override void MoveDirectory_TargetShouldBeInvalid(string sourcePath, string targetPath)
{
this.MoveFile(sourcePath, targetPath).ShouldContain(invalidPathErrorMessages);
}

public override void CreateDirectory(string path)
{
this.RunProcess(string.Format("-Command \"&{{ New-Item {0} -type directory}}\"", path));
Expand All @@ -170,37 +143,6 @@ public override string EnumerateDirectory(string path)
return this.RunProcess(string.Format("-Command \"&{{ Get-ChildItem {0} }}\"", path));
}

public override void ReplaceFile_FileShouldNotBeFound(string sourcePath, string targetPath)
{
this.ReplaceFile(sourcePath, targetPath).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteFile_FileShouldNotBeFound(string path)
{
this.DeleteFile(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteFile_AccessShouldBeDenied(string path)
{
this.DeleteFile(path).ShouldContain(permissionDeniedMessage);
this.FileExists(path).ShouldBeTrue($"{path} does not exist when it should");
}

public override void ReadAllText_FileShouldNotBeFound(string path)
{
this.ReadAllText(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteDirectory_DirectoryShouldNotBeFound(string path)
{
this.DeleteDirectory(path).ShouldContainOneOf(missingFileErrorMessages);
}

public override void DeleteDirectory_ShouldBeBlockedByProcess(string path)
{
this.DeleteDirectory(path).ShouldContain(fileUsedByAnotherProcessMessage);
}

public override long FileSize(string path)
{
return long.Parse(this.RunProcess(string.Format("-Command \"&{{ (Get-Item {0}).length}}\"", path)));
Expand Down
Loading

0 comments on commit 46598af

Please sign in to comment.