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

Commit 7fdd946

Browse files
Merge branch 'enhancements/async-git-setup' into enhancements/git-setup-download
# Conflicts: # src/tests/IntegrationTests/Git/GitSetupTests.cs
2 parents b763be7 + 9eaa803 commit 7fdd946

File tree

10 files changed

+141
-112
lines changed

10 files changed

+141
-112
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 GitHub
3+
Copyright (c) 2016-2018 GitHub
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@
118118
<Compile Include="Helpers\Constants.cs" />
119119
<Compile Include="Helpers\Validation.cs" />
120120
<Compile Include="Installer\GitInstaller.cs" />
121-
<Compile Include="Installer\ShortCircuitTask.cs" />
122121
<Compile Include="Installer\UnzipTask.cs" />
123122
<Compile Include="OutputProcessors\GitAheadBehindStatusOutputProcessor.cs" />
124123
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />

src/GitHub.Api/Installer/ShortCircuitTask.cs

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

src/GitHub.Api/Tasks/DownloadTask.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ public static WebResponse GetResponseWithoutException(this WebRequest request)
8585
}
8686
catch (WebException e)
8787
{
88-
return e.Response;
88+
if (e.Response != null)
89+
{
90+
return e.Response;
91+
}
92+
93+
throw e;
8994
}
9095
}
9196
}

src/tests/IntegrationTests/Download/DownloadTaskTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public void TestDownloadFailure()
8181
exceptionThrown.Should().NotBeNull();
8282
}
8383

84-
8584
[Test]
8685
public void TestDownloadTextTask()
8786
{
@@ -92,6 +91,26 @@ public void TestDownloadTextTask()
9291
var resultLines = result.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
9392
resultLines[0].Should().Be("# If you would like to crawl GitHub contact us at [email protected].");
9493
}
94+
95+
[Test]
96+
public void TestDownloadTextFailture()
97+
{
98+
InitializeTaskManager();
99+
100+
var downloadTask = new DownloadTextTask(CancellationToken.None, "https://ggggithub.com/robots.txt");
101+
var exceptionThrown = false;
102+
103+
try
104+
{
105+
var result = downloadTask.Start().Result;
106+
}
107+
catch (Exception e)
108+
{
109+
exceptionThrown = true;
110+
}
111+
112+
exceptionThrown.Should().BeTrue();
113+
}
95114

96115
[Test]
97116
public void TestDownloadFileAndHash()
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System.Collections.Generic;
2+
using FluentAssertions;
3+
using GitHub.Unity;
4+
using NUnit.Framework;
5+
using Rackspace.Threading;
6+
using System.Threading.Tasks;
7+
using ICSharpCode.SharpZipLib.Zip;
8+
9+
namespace IntegrationTests
10+
{
11+
class GitSetupTests : BaseGitEnvironmentTest
12+
{
13+
[Test, Category("DoNotRunOnAppVeyor")]
14+
public async Task InstallGit()
15+
{
16+
var environmentPath = NPath.CreateTempDirectory("integration-test-environment");
17+
var environment = await Initialize(TestRepoMasterDirtyUnsynchronized, environmentPath);
18+
19+
var gitSetup = new GitInstaller(environment, TaskManager.Token);
20+
var expectedPath = gitSetup.GitInstallationPath;
21+
22+
var setupDone = false;
23+
var percent = -1f;
24+
gitSetup.GitExecutablePath.FileExists().Should().BeFalse();
25+
26+
setupDone = await gitSetup.SetupIfNeeded(new Progress<float>(x => percent = x));
27+
28+
if (environment.IsWindows)
29+
{
30+
environment.GitExecutablePath = gitSetup.GitExecutablePath;
31+
32+
setupDone.Should().BeTrue();
33+
percent.Should().Be(1);
34+
35+
Logger.Trace("Expected GitExecutablePath: {0}", gitSetup.GitExecutablePath);
36+
gitSetup.GitExecutablePath.FileExists().Should().BeTrue();
37+
38+
var gitLfsDestinationPath = gitSetup.GitInstallationPath;
39+
gitLfsDestinationPath = gitLfsDestinationPath.Combine("mingw32");
40+
41+
gitLfsDestinationPath = gitLfsDestinationPath.Combine("libexec", "git-core", "git-lfs.exe");
42+
gitLfsDestinationPath.FileExists().Should().BeTrue();
43+
44+
var calculateMd5 = NPath.FileSystem.CalculateFileMD5(gitLfsDestinationPath);
45+
Assert.IsTrue(string.Compare(calculateMd5, GitInstaller.WindowsGitLfsExecutableMD5, true) == 0);
46+
47+
setupDone = await gitSetup.SetupIfNeeded(new Progress<float>(x => percent = x));
48+
setupDone.Should().BeFalse();
49+
}
50+
else
51+
{
52+
environment.GitExecutablePath = "/usr/local/bin/git".ToNPath();
53+
setupDone.Should().BeFalse();
54+
}
55+
56+
var platform = new Platform(environment);
57+
var gitEnvironment = platform.GitEnvironment;
58+
var processManager = new ProcessManager(environment, gitEnvironment, TaskManager.Token);
59+
60+
List<GitBranch> gitBranches = null;
61+
gitBranches = await processManager
62+
.GetGitBranches(TestRepoMasterDirtyUnsynchronized, environment.GitExecutablePath)
63+
.StartAsAsync();
64+
65+
gitBranches.Should().BeEquivalentTo(
66+
new GitBranch("master", "origin/master: behind 1", true),
67+
new GitBranch("feature/document", "origin/feature/document", false));
68+
}
69+
70+
71+
[Test]
72+
public void VerifyWindowsGitLfsBundle()
73+
{
74+
var environmentPath = NPath.CreateTempDirectory("integration-test-environment");
75+
76+
var gitLfsPath = environmentPath.Combine("git-lfs.exe");
77+
gitLfsPath.Exists().Should().BeFalse();
78+
79+
var inputZipFile = SolutionDirectory.Combine("PlatformResources", "windows", "git-lfs.zip");
80+
81+
var fastZip = new FastZip();
82+
fastZip.ExtractZip(inputZipFile, environmentPath, null);
83+
84+
gitLfsPath.Exists().Should().BeTrue();
85+
86+
var calculateMd5 = NPath.FileSystem.CalculateFileMD5(gitLfsPath);
87+
calculateMd5.ToLower().Should().Be(GitInstaller.WindowsGitLfsExecutableMD5.ToLower());
88+
}
89+
90+
91+
[Test]
92+
public void VerifyMacGitLfsBundle()
93+
{
94+
var environmentPath = NPath.CreateTempDirectory("integration-test-environment");
95+
96+
var gitLfsPath = environmentPath.Combine("git-lfs");
97+
gitLfsPath.Exists().Should().BeFalse();
98+
99+
var inputZipFile = SolutionDirectory.Combine("PlatformResources", "mac", "git-lfs.zip");
100+
101+
var fastZip = new FastZip();
102+
fastZip.ExtractZip(inputZipFile, environmentPath, null);
103+
104+
gitLfsPath.Exists().Should().BeTrue();
105+
106+
var calculateMd5 = NPath.FileSystem.CalculateFileMD5(gitLfsPath);
107+
calculateMd5.ToLower().Should().Be(GitInstaller.MacGitLfsExecutableMD5.ToLower());
108+
}
109+
}
110+
}

src/tests/IntegrationTests/Installer/ShortCircuitTaskTests.cs

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

src/tests/IntegrationTests/IntegrationTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<Compile Include="Git\GitClientTests.cs" />
8484
<Compile Include="IntegrationTestEnvironment.cs" />
8585
<Compile Include="Installer\GitInstallerTests.cs" />
86-
<Compile Include="Installer\ShortCircuitTaskTests.cs" />
8786
<Compile Include="ProcessManagerExtensions.cs" />
8887
<Compile Include="Process\ProcessManagerIntegrationTests.cs" />
8988
<Compile Include="Properties\AssemblyInfo.cs" />

src/tests/IntegrationTests/SetUpFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Setup()
1414

1515
Logging.LogAdapter = new MultipleLogAdapter(
1616
new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log")
17-
, new ConsoleLogAdapter()
17+
//, new ConsoleLogAdapter()
1818
);
1919
}
2020
}

src/tests/IntegrationTests/UnzipTaskTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public void UnzipTest()
1919
var cacheContainer = Substitute.For<ICacheContainer>();
2020
Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory);
2121

22-
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", TestBasePath.Combine("gip_zip_extracted"), Environment);
22+
var destinationPath = TestBasePath.Combine("git_zip").CreateDirectory();
23+
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", destinationPath, Environment);
2324

2425
Logger.Trace("ArchiveFilePath: {0}", archiveFilePath);
2526
Logger.Trace("TestBasePath: {0}", TestBasePath);
2627

27-
var extractedPath = TestBasePath.Combine("git_zip_extracted");
28-
extractedPath.CreateDirectory();
28+
var extractedPath = TestBasePath.Combine("git_zip_extracted").CreateDirectory();
2929

3030
var zipProgress = 0;
3131
Logger.Trace("Pct Complete {0}%", zipProgress);

0 commit comments

Comments
 (0)