public void ShouldNotDeleteDirectoryWhereRetainedDeployedToSame() { var journalEntries = new List <JournalEntry> { fourDayOldDeployment, fourDayOldSameLocationDeployment, twoDayOldDeployment, }; deploymentJournal.GetAllJournalEntries().Returns(journalEntries); fileSystem.FileExists(fourDayOldSameLocationDeployment.Package.DeployedFrom).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 override int Execute(string[] commandLineArguments) { Options.Parse(commandLineArguments); Guard.NotNullOrWhiteSpace(retentionPolicySet, "No retention-policy-set was specified. Please pass --retentionPolicySet \"Environments-2/projects-161/Step-Package B/machines-65/<default>\""); if (days <= 0 && releases <= 0) { throw new CommandException("A value must be provided for either --days or --releases"); } var variables = new CalamariVariableDictionary(); variables.EnrichWithEnvironmentVariables(); var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem(); var deploymentJournal = new DeploymentJournal(fileSystem, new SystemSemaphore(), variables); var clock = new SystemClock(); var retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock); retentionPolicy.ApplyRetentionPolicy(retentionPolicySet, days, releases); return(0); }
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))); }