public async Task DownloadAndVerificationWorks() { Stopwatch watch; ILogging logger; StartTest(out watch, out logger); var fileUrl = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip"); var md5Url = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip.md5"); var downloader = new Downloader(); StartTrackTime(watch, logger, md5Url); downloader.QueueDownload(fileUrl, md5Url, TestBasePath); var task = await TaskEx.WhenAny(downloader.Start().Task, TaskEx.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); Assert.IsTrue(downloader.Successful); var result = await downloader.Task; Assert.AreEqual(1, result.Count); Assert.AreEqual(TestBasePath.Combine(fileUrl.Filename), result[0].File); }
public void TaskSucceeds() { InitializeTaskManager(); var cacheContainer = Substitute.For <ICacheContainer>(); Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory); var destinationPath = TestBasePath.Combine("git_zip").CreateDirectory(); var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", destinationPath, Environment); var extractedPath = TestBasePath.Combine("git_zip_extracted").CreateDirectory(); var zipProgress = 0; Logger.Trace("Pct Complete {0}%", zipProgress); var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, Environment.FileSystem, GitInstallDetails.GitExtractedMD5, new Progress <float>(zipFileProgress => { var zipFileProgressInteger = (int)(zipFileProgress * 100); if (zipProgress != zipFileProgressInteger) { zipProgress = zipFileProgressInteger; Logger.Trace("Pct Complete {0}%", zipProgress); } })); unzipTask.Start().Wait(); extractedPath.DirectoryExists().Should().BeTrue(); }
public async Task DownloadAndVerificationWorks() { Stopwatch watch; ILogging logger; StartTest(out watch, out logger); var package = Package.Load(Environment, new UriString($"http://localhost:{server.Port}/unity/git/windows/git-lfs.json")); var downloader = new Downloader(Environment.FileSystem); downloader.QueueDownload(package.Uri, TestBasePath); StartTrackTime(watch, logger, package.Url); var task = await Task.WhenAny(downloader.Start().Task, Task.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); Assert.IsTrue(downloader.Successful); var result = await downloader.Task; Assert.AreEqual(1, result.Count); Assert.AreEqual(TestBasePath.Combine(package.Uri.Filename), result[0].File); Assert.AreEqual(package.Md5, result[0].File.CalculateMD5()); }
public void TaskFailsWhenMD5Incorect() { InitializeTaskManager(); var cacheContainer = Substitute.For <ICacheContainer>(); Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory); var destinationPath = TestBasePath.Combine("git_zip").CreateDirectory(); var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", destinationPath, Environment); var extractedPath = TestBasePath.Combine("git_zip_extracted").CreateDirectory(); var failed = false; Exception exception = null; var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, Environment.FileSystem, "AABBCCDD") .Finally((b, ex) => { failed = true; exception = ex; }); unzipTask.Start().Wait(); extractedPath.DirectoryExists().Should().BeFalse(); failed.Should().BeTrue(); exception.Should().NotBeNull(); exception.Should().BeOfType <UnzipTaskException>(); }
public void GitInstallTest() { var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory(); var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows) { GitZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipMd5Url).Filename}", GitZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipUrl).Filename}", GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipMd5Url).Filename}", GitLfsZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipUrl).Filename}", }; TestBasePath.Combine("git").CreateDirectory(); var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails); var startTask = gitInstaller.SetupGitIfNeeded(); var endTask = new FuncTask <NPath, NPath>(TaskManager.Token, (s, path) => path); startTask.OnEnd += (thisTask, path, success, exception) => thisTask.GetEndOfChain().Then(endTask); startTask.Start(); NPath?resultPath = null; Assert.DoesNotThrow(async() => resultPath = await endTask.Task); resultPath.Should().NotBeNull(); }
public void GitLfsIsInstalledIfMissingWithCustomGitPath() { var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths"); var customGitInstall = TestBasePath.Combine("CustomGitInstall").Combine(GitInstaller.GitInstallDetails.GitDirectory); var gitZipUri = new UriString($"http://localhost:{server.Port}/unity/git/windows/git-slim.zip"); var downloader = new Downloader(Environment.FileSystem); downloader.QueueDownload(gitZipUri, tempZipExtractPath); downloader.RunSynchronously(); var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory(); ZipHelper.Instance.Extract(tempZipExtractPath.Combine(gitZipUri.Filename), gitExtractPath, TaskManager.Token, null); var source = gitExtractPath; var target = customGitInstall; target.DeleteIfExists(); target.EnsureParentDirectoryExists(); source.Move(target); var gitExec = customGitInstall.Combine("cmd/git.exe"); var state = new GitInstaller.GitInstallationState(); state.GitExecutablePath = gitExec; Environment.GitInstallationState = state; var defaultGitInstall = TestBasePath.Combine("DefaultInstall"); var installDetails = new GitInstaller.GitInstallDetails(defaultGitInstall, DefaultEnvironment.OnWindows) { GitPackageFeed = "http://nope", GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}", }; var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails); state = gitInstaller.SetupGitIfNeeded(); state.Should().NotBeNull(); var gitLfsBasePath = defaultGitInstall.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory); var gitLfsExec = gitLfsBasePath.Combine("git-lfs.exe"); state.GitInstallationPath.Should().Be(customGitInstall); state.GitExecutablePath.Should().Be(gitExec); state.GitLfsInstallationPath.Should().Be(gitLfsExec.Parent); state.GitLfsExecutablePath.Should().Be(gitLfsExec); gitLfsExec.FileExists().Should().BeTrue(); Environment.GitInstallationState = state; var procTask = new SimpleProcessTask(TaskManager.Token, "something") .Configure(ProcessManager); var pathList = procTask.Process.StartInfo.EnvironmentVariables["PATH"].ToNPathList(Environment).TakeWhile(x => x != "END"); pathList.First().Should().Be(gitLfsExec.Parent); pathList.Skip(1).First().Should().Be(gitExec.Parent); }
public override void OnSetup() { base.OnSetup(); TestRepoMasterCleanUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_unsync"); TestRepoMasterCleanUnsynchronizedRussianLanguage = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync_with_russian_language"); TestRepoMasterCleanSynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync"); TestRepoMasterDirtyUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_dirty_unsync"); ZipHelper.ExtractZipFile(TestZipFilePath, TestBasePath.ToString(), CancellationToken.None); }
public virtual void OnSetup() { TestBasePath = NPath.CreateTempDirectory("integration tests"); NPath.FileSystem.SetCurrentDirectory(TestBasePath); TestRepoMasterCleanUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_unsync"); TestRepoMasterCleanUnsynchronizedRussianLanguage = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync_with_russian_language"); TestRepoMasterCleanSynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync"); TestRepoMasterDirtyUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_dirty_unsync"); TestRepoMasterTwoRemotes = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_two_remotes"); InitializeTaskManager(); }
public override void OnSetup() { base.OnSetup(); TestRepoMasterCleanUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_unsync"); TestRepoMasterCleanUnsynchronizedRussianLanguage = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync_with_russian_language"); TestRepoMasterCleanSynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync"); TestRepoMasterDirtyUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_dirty_unsync"); TestRepoMasterTwoRemotes = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_two_remotes"); InitializeTaskManager(); }
public void GitInstallWindows() { var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory(); var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows) { GitZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipMd5Url).Filename}", GitZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitZipUrl).Filename}", GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipMd5Url).Filename}", GitLfsZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstaller.GitInstallDetails.DefaultGitLfsZipUrl).Filename}", }; TestBasePath.Combine("git").CreateDirectory(); var zipHelper = Substitute.For <IZipHelper>(); zipHelper.Extract(Arg.Any <string>(), Arg.Do <string>(x => { var n = x.ToNPath(); n.EnsureDirectoryExists(); if (n.FileName == "git-lfs") { n.Combine("git-lfs" + Environment.ExecutableExtension).WriteAllText(""); } }), Arg.Any <CancellationToken>(), Arg.Any <Func <long, long, bool> >()).Returns(true); ZipHelper.Instance = zipHelper; var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails); TaskCompletionSource <GitInstaller.GitInstallationState> end = new TaskCompletionSource <GitInstaller.GitInstallationState>(); var startTask = gitInstaller.SetupGitIfNeeded().Finally((_, state) => end.TrySetResult(state)); startTask.Start(); GitInstaller.GitInstallationState result = null; Assert.DoesNotThrow(async() => result = await end.Task); result.Should().NotBeNull(); Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), result.GitInstallationPath); result.GitExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "cmd", "git" + Environment.ExecutableExtension)); result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "mingw32", "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension)); var isCustomGitExec = result.GitExecutablePath != result.GitExecutablePath; Environment.GitExecutablePath = result.GitExecutablePath; Environment.GitLfsExecutablePath = result.GitLfsExecutablePath; Environment.IsCustomGitExecutable = isCustomGitExec; var procTask = new SimpleProcessTask(TaskManager.Token, "something") .Configure(ProcessManager); procTask.Process.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString()); }
protected void InitializePlatform(NPath repoPath, NPath?environmentPath, bool enableEnvironmentTrace, bool setupGit = true) { InitializeTaskManager(); InitializeEnvironment(repoPath, environmentPath, enableEnvironmentTrace); Platform = new Platform(Environment); ProcessManager = new ProcessManager(Environment, GitEnvironment, TaskManager.Token); Platform.Initialize(ProcessManager, TaskManager); if (setupGit) { var autoResetEvent = new AutoResetEvent(false); var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath(); var installDetails = new GitInstallDetails(applicationDataPath, true); var zipArchivesPath = TestBasePath.Combine("ZipArchives").CreateDirectory(); var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment); var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment); var gitInstaller = new GitInstaller(Environment, TaskManager.Token, installDetails, gitArchivePath, gitLfsArchivePath); NPath? result = null; Exception ex = null; gitInstaller.SetupGitIfNeeded(new ActionTask <NPath>(TaskManager.Token, (b, path) => { result = path; autoResetEvent.Set(); }), new ActionTask(TaskManager.Token, (b, exception) => { ex = exception; autoResetEvent.Set(); })); autoResetEvent.WaitOne(); if (result == null) { if (ex != null) { throw ex; } throw new Exception("Did not install git"); } Environment.GitExecutablePath = result.Value; GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token); } }
public override void OnSetup() { base.OnSetup(); TestRepoMasterCleanUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_unsync"); TestRepoMasterCleanUnsynchronizedRussianLanguage = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync_with_russian_language"); TestRepoMasterCleanSynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_clean_sync"); TestRepoMasterDirtyUnsynchronized = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_dirty_unsync"); TestRepoMasterTwoRemotes = TestBasePath.Combine("IOTestsRepo", "IOTestsRepo_master_two_remotes"); Logger.Trace("Extracting Zip File to {0}", TestBasePath); ZipHelper.ExtractZipFile(TestZipFilePath, TestBasePath.ToString(), TaskManager.Token); Logger.Trace("Extracted Zip File"); }
public void GitIsInstalledIfMissing() { GitInstaller.GitInstallDetails.GitPackageFeed = $"http://localhost:{server.Port}/{GitInstaller.GitInstallDetails.GitPackageName}"; var installDetails = new GitInstaller.GitInstallDetails(TestBasePath, Environment); var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails); var result = gitInstaller.RunSynchronously(); result.Should().NotBeNull(); var expectedInstallationPath = TestBasePath.Combine("Git"); Assert.AreEqual(expectedInstallationPath, result.GitInstallationPath); result.GitExecutablePath.Should().Be(expectedInstallationPath.Combine("cmd", "git" + Environment.ExecutableExtension)); }
public async Task ResumingWorks() { Stopwatch watch; ILogging logger; StartTest(out watch, out logger); var fileSystem = NPath.FileSystem; var fileUrl = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip"); var md5Url = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip.md5"); var downloader = new Downloader(); StartTrackTime(watch, logger, md5Url); downloader.QueueDownload(fileUrl, md5Url, TestBasePath); var task = await TaskEx.WhenAny(downloader.Start().Task, TaskEx.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); var result = await downloader.Task; var downloadData = result.FirstOrDefault(); var downloadPathBytes = fileSystem.ReadAllBytes(downloadData.File); Logger.Trace("File size {0} bytes", downloadPathBytes.Length); var cutDownloadPathBytes = downloadPathBytes.Take(downloadPathBytes.Length - 1000).ToArray(); fileSystem.FileDelete(downloadData.File); fileSystem.WriteAllBytes(downloadData + ".partial", cutDownloadPathBytes); downloader = new Downloader(); StartTrackTime(watch, logger, "resuming download"); downloader.QueueDownload(fileUrl, md5Url, TestBasePath); task = await TaskEx.WhenAny(downloader.Start().Task, TaskEx.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); result = await downloader.Task; downloadData = result.FirstOrDefault(); var md5Sum = downloadData.File.CalculateMD5(); var md5 = TestBasePath.Combine(md5Url.Filename).ReadAllText(); md5Sum.Should().BeEquivalentTo(md5); }
//[Test] public void GitInstallMac() { var filesystem = Substitute.For <IFileSystem>(); DefaultEnvironment.OnMac = true; DefaultEnvironment.OnWindows = false; var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory(); var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, Environment.IsWindows) { GitZipMd5Url = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitZipMd5Url).AbsolutePath}", GitZipUrl = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitZipUrl).AbsolutePath}", GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitLfsZipMd5Url).AbsolutePath}", GitLfsZipUrl = $"http://localhost:{server.Port}/{new Uri(GitInstaller.GitInstallDetails.DefaultGitLfsZipUrl).AbsolutePath}", }; TestBasePath.Combine("git").CreateDirectory(); var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails); var startTask = gitInstaller.SetupGitIfNeeded(); var endTask = new FuncTask <GitInstaller.GitInstallationState, GitInstaller.GitInstallationState>(TaskManager.Token, (s, state) => state); startTask.OnEnd += (thisTask, path, success, exception) => thisTask.GetEndOfChain().Then(endTask); startTask.Start(); GitInstaller.GitInstallationState result = null; Assert.DoesNotThrow(async() => result = await endTask.Task); result.Should().NotBeNull(); Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), result.GitInstallationPath); result.GitExecutablePath.Should().Be(gitInstallationPath.Combine("bin", "git" + Environment.ExecutableExtension)); result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension)); var isCustomGitExec = result.GitExecutablePath != result.GitExecutablePath; Environment.GitExecutablePath = result.GitExecutablePath; Environment.GitLfsExecutablePath = result.GitLfsExecutablePath; Environment.IsCustomGitExecutable = isCustomGitExec; var procTask = new SimpleProcessTask(TaskManager.Token, "something") .Configure(ProcessManager); procTask.Process.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString()); }
public void GitInstallTest() { var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory(); var installDetails = new GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows) { GitZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstallDetails.DefaultGitZipMd5Url).Filename}", GitZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstallDetails.DefaultGitZipUrl).Filename}", GitLfsZipMd5Url = $"http://localhost:{server.Port}/{new UriString(GitInstallDetails.DefaultGitLfsZipMd5Url).Filename}", GitLfsZipUrl = $"http://localhost:{server.Port}/{new UriString(GitInstallDetails.DefaultGitLfsZipUrl).Filename}", }; TestBasePath.Combine("git").CreateDirectory(); //var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment); //var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment); var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails); var autoResetEvent = new AutoResetEvent(false); bool? result = null; NPath resultPath = null; Exception ex = null; gitInstaller.SetupGitIfNeeded(new ActionTask <NPath>(CancellationToken.None, (b, path) => { result = true; resultPath = path; autoResetEvent.Set(); }), new ActionTask(CancellationToken.None, (b, exception) => { result = false; ex = exception; autoResetEvent.Set(); })); autoResetEvent.WaitOne(); result.HasValue.Should().BeTrue(); result.Value.Should().BeTrue(); resultPath.Should().NotBeNull(); ex.Should().BeNull(); }
protected void SetupGit(NPath pathToSetupGitInto, string testName) { var installDetails = new GitInstaller.GitInstallDetails(pathToSetupGitInto, Environment.IsWindows); var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails); var state = gitInstaller.SetDefaultPaths(new GitInstaller.GitInstallationState()); Environment.GitInstallationState = state; GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token); if (installDetails.GitExecutablePath.FileExists() && installDetails.GitLfsExecutablePath.FileExists()) { return; } installDetails.GitInstallationPath.DeleteIfExists(); installDetails.GitZipPath.EnsureParentDirectoryExists(); installDetails.GitLfsZipPath.EnsureParentDirectoryExists(); AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.GitZipPath.Parent, Environment); AssemblyResources.ToFile(ResourceType.Platform, "git.json", installDetails.GitZipPath.Parent, Environment); AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.GitZipPath.Parent, Environment); AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.json", installDetails.GitZipPath.Parent, Environment); var tempZipExtractPath = TestBasePath.Combine("setup", "git_zip_extract_zip_paths").EnsureDirectoryExists(); var extractPath = tempZipExtractPath.Combine("git").CreateDirectory(); var path = new UnzipTask(TaskManager.Token, installDetails.GitZipPath, extractPath, null, Environment.FileSystem) .Catch(e => true) .RunSynchronously(); var source = path; installDetails.GitInstallationPath.EnsureParentDirectoryExists(); source.Move(installDetails.GitInstallationPath); extractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory(); path = new UnzipTask(TaskManager.Token, installDetails.GitLfsZipPath, extractPath, null, Environment.FileSystem) .Catch(e => true) .RunSynchronously(); installDetails.GitLfsInstallationPath.EnsureParentDirectoryExists(); path.Move(installDetails.GitLfsInstallationPath); }
public void GitInstallWindows() { var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory(); var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows) { GitPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitPackageName}", GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}", }; TestBasePath.Combine("git").CreateDirectory(); var zipHelper = Substitute.For <IZipHelper>(); zipHelper.Extract(Arg.Any <string>(), Arg.Do <string>(x => { var n = x.ToNPath(); n.EnsureDirectoryExists(); if (n.FileName == "git-lfs") { n.Combine("git-lfs" + Environment.ExecutableExtension).WriteAllText(""); } }), Arg.Any <CancellationToken>(), Arg.Any <Func <long, long, bool> >()).Returns(true); ZipHelper.Instance = zipHelper; var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails); var state = gitInstaller.SetupGitIfNeeded(); state.Should().NotBeNull(); Assert.AreEqual(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory), state.GitInstallationPath); state.GitExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory, "cmd", "git" + Environment.ExecutableExtension)); state.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory, "git-lfs" + Environment.ExecutableExtension)); Environment.GitInstallationState = state; var procTask = new SimpleProcessTask(TaskManager.Token, "something") .Configure(ProcessManager); procTask.Process.StartInfo.EnvironmentVariables["PATH"].Should().StartWith(gitInstallationPath.ToString()); }
protected void SetupGit(NPath pathToSetupGitInto, string testName) { var installDetails = new GitInstaller.GitInstallDetails(pathToSetupGitInto, Environment); var state = installDetails.GetDefaults(); Environment.GitInstallationState = state; GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token); if (installDetails.GitExecutablePath.FileExists() && installDetails.GitLfsExecutablePath.FileExists()) { return; } var key = installDetails.GitManifest.FileNameWithoutExtension + "_updatelastCheckTime"; Environment.UserSettings.Set(key, DateTimeOffset.Now); var localCache = TestLocation.Combine("Resources"); localCache.CopyFiles(pathToSetupGitInto, true); // skip checking for updates state.GitPackage = DugiteReleaseManifest.Load(installDetails.GitManifest, GitInstaller.GitInstallDetails.GitPackageFeed, Environment); var asset = state.GitPackage.DugitePackage; state.GitZipPath = installDetails.ZipPath.Combine(asset.Name); installDetails.GitInstallationPath.DeleteIfExists(); state.GitZipPath.EnsureParentDirectoryExists(); var gitExtractPath = TestBasePath.Combine("setup", "git_zip_extract_zip_paths").EnsureDirectoryExists(); var source = new UnzipTask(TaskManager.Token, state.GitZipPath, gitExtractPath, null, Environment.FileSystem) .RunSynchronously(); installDetails.GitInstallationPath.EnsureParentDirectoryExists(); source.Move(installDetails.GitInstallationPath); }
public void GitLfsIsInstalledIfMissing() { var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths"); var gitInstallationPath = TestBasePath.Combine("GitInstall").Combine(GitInstaller.GitInstallDetails.GitDirectory); var gitLfsInstallationPath = TestBasePath.Combine("GitInstall").Combine(GitInstaller.GitInstallDetails.GitLfsDirectory); var gitZipUri = new UriString($"http://localhost:{server.Port}/unity/git/windows/git-slim.zip"); var downloader = new Downloader(Environment.FileSystem); downloader.QueueDownload(gitZipUri, tempZipExtractPath); downloader.RunSynchronously(); var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory(); ZipHelper.Instance.Extract(tempZipExtractPath.Combine(gitZipUri.Filename), gitExtractPath, TaskManager.Token, null); var source = gitExtractPath; var target = gitInstallationPath; target.DeleteIfExists(); target.EnsureParentDirectoryExists(); source.Move(target); var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath.Parent, DefaultEnvironment.OnWindows) { GitPackageFeed = "http://nope", GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}", }; var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails); var result = gitInstaller.SetupGitIfNeeded(); result.Should().NotBeNull(); Assert.AreEqual(gitInstallationPath, result.GitInstallationPath); result.GitExecutablePath.Should().Be(gitInstallationPath.Combine("cmd", "git" + Environment.ExecutableExtension)); result.GitLfsExecutablePath.Should().Be(gitLfsInstallationPath.Combine("git-lfs" + Environment.ExecutableExtension)); }
public async Task UnzipWorks() { var cacheContainer = Substitute.For <ICacheContainer>(); Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory); InitializeTaskManager(); var destinationPath = TestBasePath.Combine("gitlfs_zip").CreateDirectory(); var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", destinationPath, Environment); var extractedPath = TestBasePath.Combine("gitlfs_zip_extracted").CreateDirectory(); var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, ZipHelper.Instance, Environment.FileSystem) .Progress(p => { }); await unzipTask.StartAwait(); extractedPath.DirectoryExists().Should().BeTrue(); }
public async Task SucceedIfEverythingIsAlreadyDownloaded() { Stopwatch watch; ILogging logger; StartTest(out watch, out logger); var fileSystem = NPath.FileSystem; var fileUrl = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip"); var md5Url = new UriString($"http://localhost:{server.Port}/git/windows/git-lfs.zip.md5"); var downloader = new Downloader(); StartTrackTime(watch, logger, md5Url); downloader.QueueDownload(fileUrl, md5Url, TestBasePath); var task = await TaskEx.WhenAny(downloader.Start().Task, TaskEx.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); var downloadData = await downloader.Task; var downloadPath = downloadData.FirstOrDefault().File; downloader = new Downloader(); StartTrackTime(watch, logger, "downloading again"); downloader.QueueDownload(fileUrl, md5Url, TestBasePath); task = await TaskEx.WhenAny(downloader.Start().Task, TaskEx.Delay(Timeout)); StopTrackTimeAndLog(watch, logger); Assert.AreEqual(downloader.Task, task); downloadData = await downloader.Task; downloadPath = downloadData.FirstOrDefault().File; var md5Sum = downloadPath.CalculateMD5(); var md5 = TestBasePath.Combine(md5Url.Filename).ReadAllText(); md5Sum.Should().BeEquivalentTo(md5); }
public async Task UnzipWorks() { var cacheContainer = Substitute.For <ICacheContainer>(); Environment = new IntegrationTestEnvironment(cacheContainer, TestBasePath, SolutionDirectory, new CreateEnvironmentOptions(TestBasePath)); InitializeTaskManager(); var expectedContent = @"Yup this is { good énough } ".Replace("\r\n", "\n"); var destinationPath = TestBasePath.Combine("unziptests").CreateDirectory(); var localCache = TestLocation.Combine("UnzipTestResources"); var archiveFilePath = localCache.Combine("testfile.zip"); var extractedPath = TestBasePath.Combine("zipextract").CreateDirectory(); var unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, ZipHelper.Instance, Environment.FileSystem); await unzipTask.StartAwait(); var expectedFile = extractedPath.Combine("embedded-git.json"); expectedFile.Parent.DirectoryExists().Should().BeTrue(); expectedFile.FileExists().Should().BeTrue(); var actualContent = expectedFile.ReadAllText(); actualContent.Should().Be(expectedContent); extractedPath = TestBasePath.Combine("tgzextract").CreateDirectory(); archiveFilePath = localCache.Combine("testfile.tgz"); unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, ZipHelper.Instance, Environment.FileSystem); await unzipTask.StartAwait(); expectedFile = extractedPath.Combine("embedded-git.json"); expectedFile.Parent.DirectoryExists().Should().BeTrue(); expectedFile.FileExists().Should().BeTrue(); expectedFile.ReadAllText().Should().Be(expectedContent); extractedPath = TestBasePath.Combine("targzextract").CreateDirectory(); archiveFilePath = localCache.Combine("testfile.tar.gz"); unzipTask = new UnzipTask(CancellationToken.None, archiveFilePath, extractedPath, ZipHelper.Instance, Environment.FileSystem); await unzipTask.StartAwait(); expectedFile = extractedPath.Combine("embedded-git.json"); expectedFile.Parent.DirectoryExists().Should().BeTrue(); expectedFile.FileExists().Should().BeTrue(); expectedFile.ReadAllText().Should().Be(expectedContent); }