8000 Merge pull request #1018 from libgit2/ntk/temp · thatfrankdev/libgit2sharp@7027de2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7027de2

Browse files
committed
Merge pull request libgit2#1018 from libgit2/ntk/temp
Sandbox test repositories in TMP
2 parents ae1b75e + ce5ab7c commit 7027de2

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

LibGit2Sharp.Tests/ShadowCopyFixture.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
1717
Assembly assembly = type.Assembly;
1818

1919
// Build a new domain which will shadow copy assemblies
20-
string cachePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
20+
string cachePath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
2121
Directory.CreateDirectory(cachePath);
2222

2323
var setup = new AppDomainSetup
@@ -51,11 +51,6 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly()
5151

5252
// ...but are currently loaded from different locations...
5353
string cachedAssemblyLocation = wrapper.AssemblyLocation;
54-
if (cachedAssemblyLocation.StartsWith("/private"))
55-
{
56-
// On OS X, sometimes you get /private/var/… instead of /var/…, but they map to the same place.
57-
cachedAssemblyLocation = cachedAssemblyLocation.Substring("/private".Length);
58-
}
5954
Assert.NotEqual(sourceAssembly.Location, cachedAssemblyLocation);
6055

6156
// ...that the assembly in the other domain is stored in the shadow copy cache...

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ private static void SetUpTestEnvironment()
7272
SubmoduleTargetTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_target_wd");
7373
AssumeUnchangedRepoWorkingDirPath = Path.Combine(sourceRelativePath, "assume_unchanged_wd");
7474
SubmoduleSmallTestRepoWorkingDirPath = Path.Combine(sourceRelativePath, "submodule_small_wd");
75+
76+
CleanupTestReposOlderThan(TimeSpan.FromMinutes(15));
77+
}
78+
79+
private static void CleanupTestReposOlderThan(TimeSpan olderThan)
80+
{
81+
var oldTestRepos = new DirectoryInfo(Constants.TemporaryReposPath)
82+
.EnumerateDirectories()
83+
.Where(di => di.CreationTimeUtc < DateTimeOffset.Now.Subtract(olderThan))
84+
.Select(di => di.FullName);
85+
86+
foreach (var dir in oldTestRepos)
87+
{
88+
DirectoryHelper.DeleteDirectory(dir);
89+
}
7590
}
7691

7792
private static bool IsFileSystemCaseSensitiveInternal()

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.IO;
23

34
namespace LibGit2Sharp.Tests.TestHelpers
45
{
56
public static class Constants
67
{
7-
public const string TemporaryReposPath = "TestRepos";
8+
public static readonly string TemporaryReposPath = BuildPath();
89
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
910
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
1011
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
@@ -30,5 +31,28 @@ public static Credentials PrivateRepoCredentials(string url, string usernameFrom
3031
{
3132
return null;
3233
}
34+
35+
public static string BuildPath()
36+
{
37+
string tempPath;
38+
39+
var unixPath = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
40+
41+
if (unixPath != null)
42+
{
43+
// We're running on Mono/*nix. Let's unwrap the path
44+
tempPath = (string)unixPath.InvokeMember("GetCompleteRealPath",
45+
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.FlattenHierarchy |
46+
System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public,
47+
null, unixPath, new object[] { Path.GetTempPath() });
48+
}
49+
else
50+
{
51+
// We're running on .Net/Windows
52+
tempPath = Path.GetTempPath();
53+
}
54+
55+
return Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
56+
}
3357
}
3458
}

0 commit comments

Comments
 (0)
0