Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit b4d3a18

Browse files
committed
Make sure git integration tests setup the right git
1 parent 3c13e7e commit b4d3a18

File tree

18 files changed

+39
-192
lines changed

18 files changed

+39
-192
lines changed

src/GitHub.Api/Helpers/AssemblyResources.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,17 @@ Each file's name is their physical path in the project.
3939
: resourceType == ResourceType.Platform ? "PlatformResources"
4040
: "Resources";
4141

42+
// all the resources are embedded in GitHub.Api
4243
var asm = Assembly.GetCallingAssembly();
43-
if (!asm.FullName.StartsWith("IntegrationTests"))
44+
if (resourceType != ResourceType.Icon)
4445
asm = typeof(AssemblyResources).Assembly;
4546
var stream = asm.GetManifestResourceStream(
4647
String.Format("GitHub.Unity.{0}{1}.{2}", type, !string.IsNullOrEmpty(os) ? "." + os : os, resource));
4748
if (stream != null)
4849
return destinationPath.Combine(resource).WriteAllBytes(stream.ToByteArray());
4950

50-
// check the GitHub.Api assembly
51-
if (!asm.FullName.StartsWith("GitHub.Api"))
52-
{
53-
asm = typeof(ApplicationManagerBase).Assembly;
54-
stream = asm.GetManifestResourceStream(
55-
String.Format("GitHub.Unity.{0}{1}.{2}", type, !string.IsNullOrEmpty(os) ? "." + os : os, resource));
56-
if (stream != null)
57-
return destinationPath.Combine(resource).WriteAllBytes(stream.ToByteArray());
58-
}
59-
51+
// if we're not in the test runner, we might be running in a Unity-compiled GitHub.Unity assembly, which doesn't
52+
// embed the resources in the assembly
6053
if (!Guard.InUnitTestRunner)
6154
{
6255
// check the filesystem

src/tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ protected void InitializeEnvironment(NPath repoPath,
7070

7171
protected void InitializePlatform(NPath repoPath,
7272
bool enableEnvironmentTrace = true,
73-
bool setupGit = true,
7473
string testName = "")
7574
{
7675
InitializeTaskManager();
@@ -79,9 +78,6 @@ protected void InitializePlatform(NPath repoPath,
7978
ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token);
8079

8180
Platform.Initialize(ProcessManager, TaskManager);
82-
83-
if (setupGit)
84-
SetupGit(Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath(), testName);
8581
}
8682

8783
protected void InitializeTaskManager()
@@ -93,12 +89,12 @@ protected void InitializeTaskManager()
9389

9490
protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
9591
bool enableEnvironmentTrace = false,
96-
bool setupGit = true,
9792
Action<IRepositoryManager> onRepositoryManagerCreated = null,
9893
[CallerMemberName] string testName = "")
9994
{
10095
InitializeEnvironment(repoPath, enableEnvironmentTrace, true);
101-
InitializePlatform(repoPath, enableEnvironmentTrace: enableEnvironmentTrace, setupGit: setupGit, testName: testName);
96+
InitializePlatform(repoPath, enableEnvironmentTrace: enableEnvironmentTrace, testName: testName);
97+
SetupGit(Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath(), testName);
10298

10399
DotGitPath = repoPath.Combine(".git");
104100

@@ -128,38 +124,38 @@ protected IEnvironment InitializePlatformAndEnvironment(NPath repoPath,
128124

129125
protected void SetupGit(NPath pathToSetupGitInto, string testName)
130126
{
131-
var autoResetEvent = new AutoResetEvent(false);
132-
133127
var installDetails = new GitInstaller.GitInstallDetails(pathToSetupGitInto, Environment.IsWindows);
134-
135-
var zipArchivesPath = pathToSetupGitInto.Combine("downloads").CreateDirectory();
136-
137-
Logger.Trace($"Saving git zips into {zipArchivesPath} and unzipping to {pathToSetupGitInto}");
138-
139-
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
140-
AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", zipArchivesPath, Environment);
141-
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
142-
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", zipArchivesPath, Environment);
143-
144-
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, null, installDetails: installDetails);
145-
146-
Exception ex = null;
147-
148-
var state = gitInstaller.SetupGitIfNeeded();
149-
var result = state.GitExecutablePath;
150-
151-
if (!result.IsInitialized)
152-
{
153-
if (ex != null)
154-
{
155-
throw ex;
156-
}
157-
158-
throw new Exception("Did not install git");
159-
}
160-
161-
Environment.GitExecutablePath = result;
128+
Environment.GitExecutablePath = installDetails.GitExecutablePath;
162129
GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
130+
131+
if (installDetails.GitExecutablePath.FileExists() && installDetails.GitLfsExecutablePath.FileExists())
132+
return;
133+
134+
installDetails.GitInstallationPath.DeleteIfExists();
135+
136+
installDetails.GitZipPath.EnsureParentDirectoryExists();
137+
installDetails.GitLfsZipPath.EnsureParentDirectoryExists();
138+
139+
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.GitZipPath.Parent, Environment);
140+
AssemblyResources.ToFile(ResourceType.Platform, "git.json", installDetails.GitZipPath.Parent, Environment);
141+
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.GitZipPath.Parent, Environment);
142+
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.json", installDetails.GitZipPath.Parent, Environment);
143+
144+
var tempZipExtractPath = TestBasePath.Combine("setup", "git_zip_extract_zip_paths").EnsureDirectoryExists();
145+
var extractPath = tempZipExtractPath.Combine("git").CreateDirectory();
146+
var path = new UnzipTask(TaskManager.Token, installDetails.GitZipPath, extractPath, null, Environment.FileSystem)
147+
.Catch(e => true)
148+
.RunWithReturn(true);
149+
var source = path;
150+
installDetails.GitInstallationPath.EnsureParentDirectoryExists();
151+
source.Move(installDetails.GitInstallationPath);
152+
153+
extractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory();
154+
path = new UnzipTask(TaskManager.Token, installDetails.GitLfsZipPath, extractPath, null, Environment.FileSystem)
155+
.Catch(e => true)
156+
.RunWithReturn(true);
157+
source = path.Combine(installDetails.GitLfsExecutable);
158+
source.Move(installDetails.GitLfsExecutablePath);
163159
}
164160

165161
[TestFixtureSetUp]

src/tests/IntegrationTests/Git/GitClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace IntegrationTests
88
{
99
[TestFixture]
10-
class GitClientTests : BaseGitTestWithHttpServer
10+
class A_GitClientTests : BaseGitTestWithHttpServer
1111
{
1212
protected override int Timeout { get; set; } = 5 * 60 * 1000;
1313

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override void OnSetup()
1818
{
1919
base.OnSetup();
2020
InitializeEnvironment(TestBasePath, false, false);
21-
InitializePlatform(TestBasePath, setupGit: false);
21+
InitializePlatform(TestBasePath);
2222
}
2323

2424
private TestWebServer.HttpServer server;
@@ -168,7 +168,7 @@ public override void OnSetup()
168168
{
169169
base.OnSetup();
170170
InitializeEnvironment(TestBasePath, false, false);
171-
InitializePlatform(TestBasePath, setupGit: false);
171+
InitializePlatform(TestBasePath);
172172
}
173173

174174
[Test]

src/tests/IntegrationTests/IntegrationTests.csproj

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@
115115
<None Include="packages.config">
116116
<SubType>Designer</SubType>
117117
</None>
118-
<EmbeddedResource Include="PlatformResources\mac\git-lfs.zip" />
119-
<EmbeddedResource Include="PlatformResources\mac\gitconfig" />
120-
<EmbeddedResource Include="PlatformResources\windows\git-lfs.zip" />
121-
<EmbeddedResource Include="PlatformResources\windows\git.zip" />
122-
<EmbeddedResource Include="PlatformResources\windows\gitconfig" />
123-
<EmbeddedResource Include="PlatformResources\linux\git-lfs.zip" />
124-
<EmbeddedResource Include="PlatformResources\linux\git-lfs.zip.md5" />
125-
<EmbeddedResource Include="PlatformResources\mac\git-lfs.zip.md5" />
126-
<EmbeddedResource Include="PlatformResources\windows\git-lfs.zip.md5" />
127-
<EmbeddedResource Include="PlatformResources\windows\git.zip.md5" />
128-
<EmbeddedResource Include="PlatformResources\linux\gitconfig" />
129118
</ItemGroup>
130119
<ItemGroup>
131120
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

src/tests/IntegrationTests/PlatformResources/linux/.placeholder

Whitespace-only changes.

src/tests/IntegrationTests/PlatformResources/linux/git-lfs.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tests/IntegrationTests/PlatformResources/linux/git-lfs.zip.md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/IntegrationTests/PlatformResources/linux/gitconfig

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/tests/IntegrationTests/PlatformResources/mac/git-lfs.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)