예제 #1
0
        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>();
        }
예제 #2
0
        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();
        }
예제 #3
0
        private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
        {
            if (!state.GitZipExists && !state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
            {
                AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
            }
            state.GitZipExists = installDetails.GitZipPath.FileExists();

            return(state);
        }
        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);
            }
        }
예제 #5
0
        protected void SetupGit(NPath pathToSetupGitInto, string testName)
        {
            var autoResetEvent = new AutoResetEvent(false);

            var installDetails = new GitInstaller.GitInstallDetails(pathToSetupGitInto, true);

            var zipArchivesPath = pathToSetupGitInto.Combine("downloads").CreateDirectory();

            Logger.Trace($"Saving git zips into {zipArchivesPath} and unzipping to {pathToSetupGitInto}");

            AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
            AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", zipArchivesPath, Environment);
            AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
            AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", zipArchivesPath, Environment);

            var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager, installDetails);

            NPath?    result = null;
            Exception ex     = null;

            var setupTask = gitInstaller.SetupGitIfNeeded();

            setupTask.OnEnd += (thisTask, _, __, ___) => {
                ((ITask <NPath>)thisTask.GetEndOfChain()).OnEnd += (t, path, success, exception) =>
                {
                    result = path;
                    ex     = exception;
                    autoResetEvent.Set();
                };
            };
            setupTask.Start();
            if (!autoResetEvent.WaitOne(TimeSpan.FromMinutes(5)))
            {
                throw new TimeoutException($"Test setup unzipping {zipArchivesPath} to {pathToSetupGitInto} timed out");
            }

            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);
        }
예제 #6
0
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
            var filesToServePath = SolutionDirectory.Combine("files");

            ApplicationConfiguration.WebTimeout = 50000;

            AssemblyResources.ToFile(ResourceType.Platform, "git.zip", filesToServePath, new DefaultEnvironment());
            AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", filesToServePath, new DefaultEnvironment());
            AssemblyResources.ToFile(ResourceType.Platform, "git.zip.md5", filesToServePath, new DefaultEnvironment());
            AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip.md5", filesToServePath, new DefaultEnvironment());

            server = new TestWebServer.HttpServer(SolutionDirectory.Combine("files"));
            Task.Factory.StartNew(server.Start);
        }
예제 #7
0
        public static DugiteReleaseManifest Load(SPath localCacheFile, UriString packageFeed, IEnvironment environment)
        {
            DugiteReleaseManifest package = null;
            //SPath localCacheFeed = environment.UserCachePath.Combine("embedded-git.json");
            var filename = localCacheFile.FileName;
            var key      = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
            var now      = DateTimeOffset.Now;

            if (!localCacheFile.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date)
            {
                localCacheFile = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath, filename)
                                 .Catch(ex => {
                    LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort());
                    return(true);
                })
                                 .RunSynchronously();

                if (localCacheFile.IsInitialized)
                {
                    environment.UserSettings.Set <DateTimeOffset>(key, now);
                }
            }

            if (!localCacheFile.IsInitialized)
            {
                // try from assembly resources
                localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment);
            }

            if (localCacheFile.IsInitialized)
            {
                try
                {
                    package = Load(localCacheFile, environment);
                }
                catch (Exception ex)
                {
                    LogHelper.Error(ex);
                }
            }
            return(package);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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();
        }