Beispiel #1
0
        public async Task ProcessReadsFromStandardInput()
        {
            var input = new List <string> {
                "Hello",
                "World\u001A"
            };

            var expectedOutput = "Hello";

            var procTask = new SimpleProcessTask(TestApp, @"-s 100 -i", Token)
                           .Configure(ProcessManager, true);

            procTask.OnStartProcess += proc =>
            {
                foreach (var item in input)
                {
                    proc.StandardInput.WriteLine(item);
                }
                proc.StandardInput.Close();
            };

            var chain = procTask
                        .Finally((s, e, d) => d);

            var output = await chain.StartAsAsync();

            Assert.AreEqual(expectedOutput, output);
        }
        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);
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
        //[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 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());
        }
Beispiel #6
0
        public async Task ProcessReturningErrorThrowsException()
        {
            var       success        = false;
            Exception thrown         = null;
            var       output         = new List <string>();
            var       expectedOutput = new List <string> {
                "one name"
            };

            var task = new SimpleProcessTask(TestApp, @"-s 100 -d ""one name""", Token).Configure(ProcessManager)
                       .Catch(ex => thrown = ex)
                       .Then((s, d) => output.Add(d))
                       .Then(new SimpleProcessTask(TestApp, @"-e kaboom -r -1", Token).Configure(ProcessManager))
                       .Catch(ex => thrown = ex)
                       .Then((s, d) => output.Add(d))
                       .Finally((s, e) => success = s);

            await task.StartAsAsyncWithoutThrowing();

            Assert.IsFalse(success);
            CollectionAssert.AreEqual(expectedOutput, output);
            Assert.IsNotNull(thrown);
            Assert.AreEqual("kaboom", thrown.Message);
        }