Skip to content

Commit

Permalink
FunctionalTests: support variable local cache root
Browse files Browse the repository at this point in the history
We update the CloneWithDefaultLocalCacheLocation() functional
test so it accommodates variable local cache paths on Linux,
depending on whether $XDG_CACHE_HOME is set or not.  This allows
the test to succeed on developer systems where we want to avoid
polluting the default ~/.cache/scalar directory during test runs
and so set $XDG_CACHE_HOME explicitly.

Note that the new ScalarTestConfig.DefaultLocalCacheRoot accessor
returns a path on Windows which should be "C:\.scalarCache",
to match what would be supplied by the TryGetDefaultLocalCacheRoot()
method of the WindowsPlatform if it were passed the default
functional test enlistment root path.  However, this Windows-
specific DefaultLocalCacheRoot value is unused, as the only
functional test which uses it is CloneWithDefaultLocalCacheLocation()
and that test belongs to the POSIXOnly category.
  • Loading branch information
chrisd8088 committed Sep 11, 2020
1 parent 9e859df commit a4cee25
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
36 changes: 36 additions & 0 deletions Scalar.FunctionalTests/ScalarTestConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Scalar.FunctionalTests
{
Expand All @@ -10,6 +12,40 @@ public static class ScalarTestConfig

public static string LocalCacheRoot { get; set; }

public static string DefaultLocalCacheRoot {
get
{
string homeDirectory = null;
string cachePath = ".scalarCache";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
homeDirectory = Path.GetPathRoot(Properties.Settings.Default.EnlistmentRoot);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
homeDirectory = Environment.GetEnvironmentVariable("HOME");
}
else
{
// On Linux we use a local cache path per the XDG Base Directory Specification.
homeDirectory = Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
if (!string.IsNullOrEmpty(homeDirectory))
{
cachePath = "scalar";
}
else
{
homeDirectory = Environment.GetEnvironmentVariable("HOME");
cachePath = Path.Combine(".cache", "scalar");
}

}

return Path.Combine(homeDirectory, cachePath);
}
}

public static object[] FileSystemRunners { get; set; }

public static object[] GitRepoTestsValidateWorkTree { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public void SparseCloneWithNoFetchOfCommitsAndTreesSucceeds()
public void CloneWithDefaultLocalCacheLocation()
{
FileSystemRunner fileSystem = FileSystemRunner.DefaultRunner;
string homeDirectory = Environment.GetEnvironmentVariable("HOME");
homeDirectory.ShouldBeADirectory(fileSystem);
string defaultLocalCacheRoot = ScalarTestConfig.DefaultLocalCacheRoot;
fileSystem.CreateDirectory(defaultLocalCacheRoot);
defaultLocalCacheRoot.ShouldBeADirectory(fileSystem);

string newEnlistmentRoot = ScalarFunctionalTestEnlistment.GetUniqueEnlistmentRoot();

Expand All @@ -80,8 +81,7 @@ public void CloneWithDefaultLocalCacheLocation()

string gitObjectsRoot = ScalarHelpers.GetObjectsRootFromGitConfig(Path.Combine(newEnlistmentRoot, "src"));

string defaultScalarCacheRoot = Path.Combine(homeDirectory, ".scalarCache");
gitObjectsRoot.StartsWith(defaultScalarCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {homeDirectory}");
gitObjectsRoot.StartsWith(defaultLocalCacheRoot, StringComparison.Ordinal).ShouldBeTrue($"Git objects root did not default to using {defaultLocalCacheRoot}");

RepositoryHelpers.DeleteTestDirectory(newEnlistmentRoot);
}
Expand Down

0 comments on commit a4cee25

Please sign in to comment.