public void ShouldNotDeleteDirectoryWhereRetainedDeployedToSame() { var journalEntries = new List <JournalEntry> { fourDayOldDeployment, fourDayOldSameLocationDeployment, twoDayOldDeployment, }; deploymentJournal.GetAllJournalEntries().Returns(journalEntries); fileSystem.FileExists(fourDayOldSameLocationDeployment.ExtractedFrom).Returns(true); fileSystem.DirectoryExists(fourDayOldSameLocationDeployment.ExtractedTo).Returns(true); const int days = 3; retentionPolicy.ApplyRetentionPolicy(policySet1, days, null); // Ensure the directories are the same Assert.AreEqual(twoDayOldDeployment.ExtractedTo, fourDayOldSameLocationDeployment.ExtractedTo); // The old directory was not removed... fileSystem.DidNotReceive().DeleteDirectory(Arg.Is <string>(s => s.Equals(fourDayOldSameLocationDeployment.ExtractedTo))); // ...despite being removed from the journal deploymentJournal.Received().RemoveJournalEntries(Arg.Is <IEnumerable <string> >(ids => ids.Contains(fourDayOldSameLocationDeployment.Id))); // and unique directory still removed fileSystem.Received().DeleteDirectory(Arg.Is <string>(s => s.Equals(fourDayOldDeployment.ExtractedTo))); }
public void ShouldDeleteScriptAfterExecution() { var convention = CreateConvention("PreDeploy"); convention.Install(deployment); scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1")), deployment.Variables, runner); fileSystem.Received().DeleteFile(TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1"), Arg.Any <FailureOptions>()); }
public void ShouldDeleteScriptsAfterExecution() { var preDeployPs1 = TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1"); var preDeploySh = TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.sh"); var convention = CreateConvention("PreDeploy"); convention.Install(deployment); scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == preDeployPs1), deployment.Variables, runner); fileSystem.Received().DeleteFile(preDeployPs1, Arg.Any <FailureOptions>()); fileSystem.Received().DeleteFile(preDeploySh, Arg.Any <FailureOptions>()); log.StandardOut.Should().ContainMatch($"Found 2 PreDeploy scripts. Selected {preDeployPs1} based on OS preferential ordering: CSharp, PowerShell, Bash"); }
public void ShouldRunScriptAtAppropriateStage() { const string stage = DeploymentStages.PostDeploy; const string scriptBody = "lorem ipsum blah blah blah"; var scriptName = ConfiguredScriptConvention.GetScriptName(stage, "ps1"); var scriptPath = Path.Combine(stagingDirectory, scriptName); variables.Set(scriptName, scriptBody); var convention = CreateConvention(stage); scriptEngine.Execute(scriptPath, variables, commandLineRunner).Returns(new CommandResult("", 0)); convention.Install(deployment); fileSystem.Received().OverwriteFile(scriptPath, scriptBody); scriptEngine.Received().Execute(scriptPath, variables, commandLineRunner); }
public void ShouldDeleteScriptAfterExecution() { var convention = CreateConvention("PreDeploy"); convention.Install(deployment); engine.Received().Execute("C:\\App\\MyApp\\PreDeploy.ps1", deployment.Variables, runner); fileSystem.Received().DeleteFile("C:\\App\\MyApp\\PreDeploy.ps1", Arg.Any <DeletionOptions>()); }
public void ShouldRunScriptAtAppropriateStage() { const string stage = DeploymentStages.PostDeploy; const string scriptBody = "lorem ipsum blah blah blah"; var scriptName = ConfiguredScriptConvention.GetScriptName(stage, ScriptSyntax.PowerShell); var scriptPath = Path.Combine(stagingDirectory, scriptName); var script = new Script(scriptPath); variables.Set(scriptName, scriptBody); var convention = CreateConvention(stage); scriptEngine.Execute(Arg.Any <Script>(), variables, commandLineRunner).Returns(new CommandResult("", 0)); convention.Install(deployment); fileSystem.Received().WriteAllBytes(scriptPath, Arg.Any <byte[]>()); scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == scriptPath), variables, commandLineRunner); }
public void ShouldKeepDeploymentsForSpecifiedDays() { const int days = 3; retentionPolicy.ApplyRetentionPolicy(policySet1, days, null); // The older artifacts should have been removed fileSystem.Received().DeleteDirectory(fourDayOldDeployment.ExtractedTo); fileSystem.Received().DeleteFile(fourDayOldDeployment.ExtractedFrom, Arg.Any <DeletionOptions>()); // The newer artifacts, and those from the non-matching policy-set, should have been kept // In other words, nothing but the matching deployment should have been removed fileSystem.DidNotReceive().DeleteDirectory(Arg.Is <string>(s => !s.Equals(fourDayOldDeployment.ExtractedTo))); fileSystem.DidNotReceive().DeleteFile(Arg.Is <string>(s => !s.Equals(fourDayOldDeployment.ExtractedFrom)), Arg.Any <DeletionOptions>()); // The older entry should have been removed from the journal deploymentJournal.Received().RemoveJournalEntries(Arg.Is <IEnumerable <string> >(ids => ids.Count() == 1 && ids.Contains(fourDayOldDeployment.Id))); }
public void ShouldCreateScriptFileIfNotExists() { const string deployStage = "BeforePostDeploy"; const string feature = "doTheThing"; var scriptPath = Path.Combine(stagingDirectory, FeatureScriptConvention.GetScriptName(feature, deployStage, "ps1")); variables.Set(SpecialVariables.Package.EnabledFeatures, feature); Arrange(new List <string> { feature }, deployStage); fileSystem.FileExists(scriptPath).Returns(false); var convention = CreateConvention(deployStage); scriptEngine.Execute(scriptPath, variables, commandLineRunner).Returns(new CommandResult("", 0)); convention.Install(deployment); fileSystem.Received().OverwriteFile(scriptPath, scriptContents); }
public void ShouldCopyFilesWhenCustomInstallationDirectoryIsSupplied() { variables.Set(SpecialVariables.Package.CustomInstallationDirectory, customInstallationDirectory); CreateConvention().Install(deployment); fileSystem.Received().CopyDirectory(stagingDirectory, customInstallationDirectory); }