public void CreateVm_RemoveVm_Works()
        {
            var fs         = CakeFixtures.CkFileSystem;
            var workingDir = new DirectoryPath(this.TestContext.DeploymentDirectory);
            var vmName     = string.Format(TestVboxHelper.TestBoxNameTemplate, "CreateVm_Works");
            var diskName   = $"{vmName}.vdi";

            var machine = new TestVboxHelper.TestMachine()
            {
                Created = true,
                HdFile  = diskName,
                Name    = vmName
            };

            using (var boxHelper = new TestVboxHelper(machine, workingDir))
            {
                var runner = this.GetRunner();

                Assert.IsFalse(runner.Vms.Any(t => t.Name.Equals(vmName)), "Test Vm Shouldn't Exist Yet");

                IProcess processResult = null;

                runner
                .FromPath(workingDir)
                .CreateVm(config =>
                {
                    config.VmName  = vmName;
                    config.OsType  = "Linux";
                    var ctlSetting = config.AddControllerSetting("SATA", "sata", "IntelAHCI");
                    ctlSetting.AddDiskSetting($"{vmName}.vdi");
                },
                          proc =>
                {
                    processResult = proc;
                });

                Assert.IsNotNull(processResult, "Failed to get process result after create");
                Assert.AreEqual(0, processResult.GetExitCode(), "Error while creating VM");
                Assert.IsTrue(fs.Exist(workingDir.CombineWithFilePath(new FilePath(diskName))),
                              "VM disk is missing");

                Assert.IsTrue(runner.Vms.Any(t => t.Name.Equals(vmName)), "Test Vm Should Exist Now");

                processResult = null;
                runner.RemoveVm(vmName, proc =>
                {
                    processResult = proc;

                    Assert.IsNotNull(processResult, "Failed to get process result after unregister");
                    Assert.AreEqual(0, processResult.GetExitCode(), "Error while removing VM");
                    Assert.IsFalse(fs.Exist(workingDir.CombineWithFilePath(new FilePath(diskName))),
                                   "VM disk should be missing");
                });

                Assert.IsFalse(runner.Vms.Any(t => t.Name.Equals(vmName)), "Test Vm Be Removed Now");
            }
        }
Exemplo n.º 2
0
        public OctopusDeployReleaseCreatorFixture(FilePath toolPath = null, bool defaultToolExist = true)
        {
            Process = Substitute.For <IProcess>();
            Process.GetExitCode().Returns(0);

            ProcessRunner = Substitute.For <IProcessRunner>();
            ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process);

            Environment = Substitute.For <ICakeEnvironment>();
            Environment.WorkingDirectory.Returns("/Working");

            Globber = Substitute.For <IGlobber>();
            Globber.Match("./tools/**/Octo.exe").Returns(new[] { (FilePath)"/Working/tools/Octo.exe" });

            FileSystem = Substitute.For <IFileSystem>();
            FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == "/Working/tools/Octo.exe")).Returns(defaultToolExist);

            if (toolPath != null)
            {
                FileSystem.Exist(Arg.Is <FilePath>(a => a.FullPath == toolPath.FullPath)).Returns(true);
            }

            ProjectName = "testProject";
            Settings    = new CreateReleaseSettings
            {
                Server = "http://octopus",
                ApiKey = "API-12345"
            };
        }
Exemplo n.º 3
0
        private void ExecuteProcess(FilePath filePath, ProcessArgumentBuilder arguments, int timeout = DefaultTimeoutMs)
        {
            try
            {
                // Start Runner
                filePath = filePath.MakeAbsolute(_Environment.WorkingDirectory);

                IProcess process = _Runner.Start(filePath, new ProcessSettings()
                {
                    Arguments             = arguments,
                    RedirectStandardError = true
                });

                process.WaitForExit(timeout);

                // Check for Errors
                IEnumerable <string> errors = process.GetStandardError();

                if (errors.Any())
                {
                    throw new TopshelfException(string.Join(",", errors), process.GetExitCode());
                }
            }
            catch (Exception ex)
            {
                if (!(ex is TimeoutException))
                {
                    throw;
                }

                _Log.Warning("Process timed out!");
            }
        }
Exemplo n.º 4
0
        protected bool ExecuteProcess(ProcessArgumentBuilder processArgumentBuilder, TSettings settings)
        {
            IProcess process = RunProcess(settings, processArgumentBuilder);

            process.WaitForExit();
            return(process.GetExitCode() == 0);
        }
        public void Build(string target, ElectronBuilderArguments userArgs)
        {
            FilePath      projectPath      = this.context.GuiCsProject;
            DirectoryPath workingDirectory = projectPath.GetDirectory();
            DirectoryPath outputDirectory  = this.context.DesktopDistributionPath.Combine(target);

            var arguments = ProcessArgumentBuilder.FromStrings(
                new string[]
            {
                "build",
                $"/target {target}",
                // $"/absolute-path \"{outputDirectory}\"", // <- Doesn't work.  Need to use the manifest file to specify this.
                $"/electron-params --publish=never",     // <- Never publish, otherwise Jenkins tries to talk to GitHub.
                $"/version {MedituConstants.VersionString}",
                $"/p:Version={MedituConstants.VersionString}",
                $"/p:AssemblyVersion={MedituConstants.VersionString}",
                $"/p:FileVersion={MedituConstants.VersionString}"
            }
                );

            var processSettings = new ProcessSettings
            {
                Arguments        = arguments,
                WorkingDirectory = workingDirectory
            };

            this.context.EnsureDirectoryExists(outputDirectory);
            this.context.CleanDirectory(outputDirectory);

            FilePath electronizeExe = userArgs.ElectronizePath ?? new FilePath("electronize");

            context.Information($"Building desktop application for {target}");
            CreateManifestFile(projectPath, outputDirectory, workingDirectory);

            using (IProcess proc = this.context.ProcessRunner.Start(electronizeExe, processSettings))
            {
                proc.WaitForExit();
                if (proc.GetExitCode() != 0)
                {
                    throw new Exception("electronize exited with exit code: " + proc.GetExitCode());
                }
            }
        }
Exemplo n.º 6
0
            public void ShouldThrowIfProcessHasANonZeroExitCode(
                [Frozen] IProcess process,
                [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);
                process.GetExitCode().Returns(3);

                sut.Invoking(s => s.Run())
                .ShouldThrow <CakeException>()
                .WithMessage("Chutzpah: Process returned an error (exit code 3).");
            }
Exemplo n.º 7
0
            public void ShouldBuildEmptyCommand([Frozen] IProcess process,
                                                [Frozen] IProcessRunner processRunner,
                                                [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                process.GetExitCode().Returns(0);
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);

                sut.Run();

                processRunner.Received(1)
                .Start(Arg.Any <FilePath>(),
                       Arg.Is <ProcessSettings>(p => p.Arguments.Render() == string.Empty));
            }
Exemplo n.º 8
0
            public void ShouldBuildCommandWithTestFilePath([Frozen] IProcess process,
                                                           [Frozen] IProcessRunner processRunner,
                                                           [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                process.GetExitCode().Returns(0);
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);

                sut.Run((FilePath)"mytests.js");

                processRunner.Received(1)
                .Start(Arg.Any <FilePath>(),
                       Arg.Is <ProcessSettings>(p => p.Arguments.Render() == "mytests.js"));
            }
Exemplo n.º 9
0
        private void Handle(IProcess process)
        {
            var exitCode    = process.GetExitCode();
            var errorOutput = process.GetStandardError().ToList();
            var output      = process.GetStandardOutput().ToList();

            if (errorOutput.Any())
            {
                throw new SystemctlException(exitCode, errorOutput);
            }

            Handle(output);
        }
Exemplo n.º 10
0
            public void ShouldSetWorkingDirectory([Frozen] ICakeEnvironment environment,
                                                  [Frozen] IProcess process,
                                                  [Frozen] IProcessRunner processRunner,
                                                  [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                environment.WorkingDirectory.Returns("/Working");
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);
                process.GetExitCode().Returns(0);

                sut.Run();

                processRunner.Received(1)
                .Start(Arg.Any <FilePath>(),
                       Arg.Is <ProcessSettings>(ps => ps.WorkingDirectory.FullPath == "/Working"));
            }
Exemplo n.º 11
0
            public void ShouldOpenInNonDefaultBrowser([Frozen] IProcess process,
                                                      [Frozen] IProcessRunner processRunner,
                                                      [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                process.GetExitCode().Returns(0);
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);

                var settings = new ChutzpahSettings
                {
                    LaunchInBrowser = ChutzpahBrowser.Chrome
                };

                sut.Run(settings: settings);

                processRunner.Received(1)
                .Start(Arg.Any <FilePath>(),
                       Arg.Is <ProcessSettings>(
                           p => p.Arguments.Render() == "/openInBrowser Chrome"));
            }
        public void RemoveVm_DiskOnly()
        {
            var fs         = CakeFixtures.CkFileSystem;
            var workingDir = new DirectoryPath(this.TestContext.DeploymentDirectory);
            var vmName     = string.Format(TestVboxHelper.TestBoxNameTemplate, "RemoveVm_DiskOnly");

            workingDir = workingDir.Combine(new DirectoryPath(vmName));
            var dir = fs.GetDirectory(workingDir);

            dir.Create();

            var diskName = $"{vmName}.vdi";

            var machine = new TestVboxHelper.TestMachine()
            {
                Created = true,
                HdFile  = diskName,
                Name    = vmName
            };

            using (var boxHelper = new TestVboxHelper(machine, workingDir))
            {
                boxHelper.CreateDisk(diskName);
                var runner = this.GetRunner();

                Assert.IsFalse(runner.Vms.Any(t => t.Name.Equals(vmName)), "Test Vm Shouldn't Exist");
                Assert.IsTrue(fs.Exist(workingDir.CombineWithFilePath(new FilePath(diskName))),
                              "VM disk is missing");

                IProcess processResult = null;
                runner.RemoveVm(vmName, proc =>
                {
                    processResult = proc;

                    var stderr = string.Join("\n", processResult.GetStandardError());
                    Assert.AreEqual(0, processResult.GetExitCode(), "Process result return non zero code.");
                });

                Assert.IsFalse(fs.Exist(workingDir.CombineWithFilePath(new FilePath(diskName))),
                               "VM disk should be removed");
            }
        }
Exemplo n.º 13
0
            public void ShouldUseProvidedSettings([Frozen] IProcess process,
                                                  [Frozen] IProcessRunner processRunner,
                                                  [Frozen] IFileSystem fileSystem, ChutzpahRunner sut)
            {
                process.GetExitCode().Returns(0);
                fileSystem.Exist(Arg.Any <FilePath>()).Returns(true);

                var settings = new ChutzpahSettings
                {
                    NoLogo = true,
                    EnableCoverageCollection = true,
                    FailOnError                = true,
                    ForceTeamCityMode          = true,
                    CoverageHtmlOutputFile     = @"c:\temp\Code Coverage\coverage.html",
                    LaunchInBrowser            = ChutzpahBrowser.DefaultBrowser,
                    JUnitXmlResultsFile        = "junitResults.xml",
                    LcovResultsFile            = "lcov.dat",
                    VisualStudioTrxResultsFile = "testResults.trx",
                    NUnit2XmlResultsFile       = "nunit.xml",
                    MaxParallelism             = 1,
                    OutputRunningTestCount     = false,
                    PrintDebugInfo             = true,
                    Trace               = true,
                    ShowFailureReport   = true,
                    AdditionalTestPaths = { (FilePath)"testfile.js", (DirectoryPath)"tests" }
                };

                sut.Run(settings: settings);

                processRunner.Received(1)
                .Start(Arg.Any <FilePath>(),
                       Arg.Is <ProcessSettings>(
                           p =>
                           p.Arguments.Render() ==
                           "/nologo /coverage /failOnError /teamcity /coveragehtml " +
                           "\"c:/temp/Code Coverage/coverage.html\" /openInBrowser " +
                           "/junit \"junitResults.xml\" /lcov \"lcov.dat\" /trx \"testResults.trx\" " +
                           "/nunit2 \"nunit.xml\" /parallelism 1 /silent /debug /trace " +
                           "/showFailureReport /path \"testfile.js\" /path \"tests\""));
            }
 public int WaitForExit()
 {
     process.WaitForExit();
     return(process.GetExitCode());
 }