Exemple #1
0
        public void SetUp()
        {
            var variables = new CalamariVariables();

            service    = Substitute.For <IStructuredConfigVariablesService>();
            deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), variables);
        }
Exemple #2
0
        public void ShouldPerformSubstitutions()
        {
            string glob        = "**\\*config.json";
            string actualMatch = "config.json";


            var variables = new CalamariVariables();

            variables.Set(PackageVariables.SubstituteInFilesTargets, glob);
            variables.Set(PackageVariables.SubstituteInFilesEnabled, true.ToString());

            var deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("packages"), variables)
            {
                StagingDirectory = StagingDirectory
            };

            var fileSystem = Substitute.For <ICalamariFileSystem>();

            fileSystem.EnumerateFilesWithGlob(StagingDirectory, glob).Returns(new[] { Path.Combine(StagingDirectory, actualMatch) });

            var substituter = Substitute.For <IFileSubstituter>();

            new SubstituteInFiles(fileSystem, substituter, variables)
            .SubstituteBasedSettingsInSuppliedVariables(deployment);

            substituter.Received().PerformSubstitution(Path.Combine(StagingDirectory, actualMatch), variables);
        }
        public void ShouldFindAndCallPreDeployScripts()
        {
            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);
        }
        public void ShouldDeleteScriptAfterCleanupExecution()
        {
            var convention = CreateRollbackConvention("DeployFailed");

            convention.Cleanup(deployment);
            fileSystem.Received().DeleteFile(TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.ps1"), Arg.Any <FailureOptions>());
        }
        public void ShouldRunScriptOnRollbackExecution()
        {
            var convention = CreateRollbackConvention("DeployFailed");

            convention.Rollback(deployment);
            scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.ps1")), deployment.Variables, runner);
        }
        public void ShouldFindAndCallModifyOnAllTargetFiles()
        {
            var targetFiles = new[]
            {
                "config.json",
                "config.dev.json",
                "config.prod.json"
            };

            fileSystem.EnumerateFiles(Arg.Any <string>(), "config.json")
            .Returns(new[] { targetFiles[0] }.Select(t => TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0", t)));
            fileSystem.EnumerateFiles(Arg.Any <string>(), "config.*.json")
            .Returns(targetFiles.Skip(1).Select(t => TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0", t)));

            deployment.Variables.Set(SpecialVariables.Package.JsonConfigurationVariablesEnabled, "true");
            deployment.Variables.Set(SpecialVariables.Package.JsonConfigurationVariablesTargets, string.Join(Environment.NewLine, "config.json", "config.*.json"));

            var convention = new JsonConfigurationVariablesConvention(configurationVariableReplacer, fileSystem);

            convention.Install(deployment);

            foreach (var targetFile in targetFiles)
            {
                configurationVariableReplacer.Received()
                .ModifyJsonFile(TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0", targetFile), deployment.Variables);
            }
        }
        public void ShouldExtractToVersionedFolderWithDefaultPath()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());

            convention.Install(new RunningDeployment(PackageLocation, variables));

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.StringEnding(Path.Combine("Acme.Web", "1.0.0")));
        }
        public void ShouldFindAndCallPackagedScripts()
        {
            var convention = CreateConvention("Deploy");

            convention.Install(deployment);
            scriptEngine.Received().Execute(TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.ps1"), deployment.Variables, runner);
            scriptEngine.Received().Execute(TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.csx"), deployment.Variables, runner);
        }
        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 ShouldExtractToVersionedFolderWithDefaultPath()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());

            extractPackage.ExtractToApplicationDirectory(PathToPackage);

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Does.EndWith(Path.Combine("Acme.Web", "1.0.0")));
        }
        public void ShouldNotDeleteDeployFailedScriptAfterExecutionIfSpecialVariableIsSet()
        {
            deployment.Variables.Set(SpecialVariables.DeleteScriptsOnCleanup, false.ToString());
            var convention = CreateRollbackConvention("DeployFailed");

            convention.Cleanup(deployment);
            fileSystem.DidNotReceive().DeleteFile(TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.ps1"), Arg.Any <FailureOptions>());
        }
        public void ShouldExtractToEnvironmentSpecificFolderIfProvided()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());
            variables.Set("Octopus.Environment.Name", "Production");

            extractPackage.ExtractToApplicationDirectory(PathToPackage);

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Does.EndWith(Path.Combine("Production", "Acme.Web", "1.0.0")));
        }
        public void ShouldRemoveInvalidPathCharsFromEnvironmentName()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());
            variables.Set("Octopus.Environment.Name", "Production! Tokyo");

            convention.Install(new RunningDeployment(PackageLocation, variables));

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.StringEnding(Path.Combine("Production Tokyo", "Acme.Web", "1.0.0")));
        }
        public void ShouldNotDeletePostDeployScriptAfterExecutionIfSpecialVariableIsSet()
        {
            deployment.Variables.Set(SpecialVariables.DeleteScriptsOnCleanup, false.ToString());
            var convention = CreateConvention("PostDeploy");

            convention.Install(deployment);
            scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.ps1")), deployment.Variables, runner);
            fileSystem.DidNotReceive().DeleteFile(TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.ps1"), Arg.Any <FailureOptions>());
        }
        public void ShouldExtractToEnvironmentSpecificFolderIfProvided()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());
            variables.Set("Octopus.Environment.Name", "Production");

            convention.Install(new RunningDeployment(PackageLocation, variables));

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.StringEnding(Path.Combine("Production", "Acme.Web", "1.0.0")));
        }
        public void ShouldRemoveInvalidPathCharsFromEnvironmentName()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());
            variables.Set("Octopus.Environment.Name", "Production! Tokyo");

            extractPackage.ExtractToApplicationDirectory(PathToPackage);

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Does.EndWith(Path.Combine("Production Tokyo", "Acme.Web", "1.0.0")));
        }
        public void ShouldPrefixAppPathIfSet()
        {
            var rootPath = TestEnvironment.ConstructRootedPath("MyApp");

            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", rootPath);

            convention.Install(new RunningDeployment(PackageLocation, variables));

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.EqualTo(Path.Combine(rootPath, "Acme.Web", "1.0.0")));
        }
        public void SetUp()
        {
            var variables = new CalamariVariableDictionary();

            variables.Set(SpecialVariables.OriginalPackageDirectoryPath, TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0"));
            deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), variables);
            configurationVariableReplacer = Substitute.For <IJsonConfigurationVariableReplacer>();
            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.DirectoryExists(Arg.Any <string>()).Returns(false);
        }
        public void ShouldPrefixAppPathIfSet()
        {
            var rootPath = TestEnvironment.ConstructRootedPath("MyApp");

            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", rootPath);

            extractPackage.ExtractToApplicationDirectory(PathToPackage);

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.EqualTo(Path.Combine(rootPath, "Acme.Web", "1.0.0")));
        }
Exemple #20
0
        public void SetUp()
        {
            fileSystem  = Substitute.For <ICalamariFileSystem>();
            substituter = Substitute.For <IFileSubstituter>();
            variables   = new CalamariVariableDictionary();

            deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("packages"), variables)
            {
                StagingDirectory = StagingDirectory
            };
        }
        public void ShouldFindAndCallModifyOnTargetFile()
        {
            fileSystem.EnumerateFiles(Arg.Any <string>(), "appsettings.environment.json")
            .Returns(new[] { TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0", "appsettings.environment.json") });

            deployment.Variables.Set(SpecialVariables.Package.JsonConfigurationVariablesEnabled, "true");
            deployment.Variables.Set(SpecialVariables.Package.JsonConfigurationVariablesTargets, "appsettings.environment.json");
            var convention = new JsonConfigurationVariablesConvention(configurationVariableReplacer, fileSystem);

            convention.Install(deployment);
            configurationVariableReplacer.Received().ModifyJsonFile(TestEnvironment.ConstructRootedPath("applications", "Acme", "1.0.0", "appsettings.environment.json"), deployment.Variables);
        }
Exemple #22
0
        public void ShouldRunPreferredScriptOnRollbackExecution()
        {
            var deployFailedPs1 = TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.ps1");
            var deployFailedSh  = TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.sh");

            var convention = CreateRollbackConvention("DeployFailed");

            convention.Rollback(deployment);
            scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == deployFailedPs1), deployment.Variables, runner);
            scriptEngine.DidNotReceive().Execute(Arg.Is <Script>(s => s.File == deployFailedSh), deployment.Variables, runner);
            log.StandardOut.Should().ContainMatch($"Found 2 DeployFailed scripts. Selected {deployFailedPs1} based on OS preferential ordering: CSharp, PowerShell, Bash");
        }
Exemple #23
0
        public void ShouldFindAndCallPreferredPreDeployScript()
        {
            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);
            scriptEngine.DidNotReceive().Execute(Arg.Is <Script>(s => s.File == preDeploySh), deployment.Variables, runner);
            log.StandardOut.Should().ContainMatch($"Found 2 PreDeploy scripts. Selected {preDeployPs1} based on OS preferential ordering: CSharp, PowerShell, Bash");
        }
Exemple #24
0
        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 ShouldAppendToVersionedFolderIfAlreadyExisting()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());

            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0")))).Returns(true);
            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0_1")))).Returns(true);
            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0_2")))).Returns(true);


            extractPackage.ExtractToApplicationDirectory(PathToPackage);

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Does.EndWith(Path.Combine("Acme.Web", "1.0.0_3")));
        }
        public void ShouldAppendToVersionedFolderIfAlreadyExisting()
        {
            variables.Set("Octopus.Tentacle.Agent.ApplicationDirectoryPath", TestEnvironment.ConstructRootedPath());

            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0")))).Returns(true);
            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0_1")))).Returns(true);
            fileSystem.DirectoryExists(Arg.Is <string>(path => path.EndsWith(Path.Combine("Acme.Web", "1.0.0_2")))).Returns(true);


            convention.Install(new RunningDeployment(PackageLocation, variables));

            Assert.That(variables.Get("OctopusOriginalPackageDirectoryPath"), Is.StringEnding(Path.Combine("Acme.Web", "1.0.0_3")));
        }
Exemple #27
0
        public void SetUp()
        {
            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.EnumerateFiles(Arg.Any <string>(), Arg.Any <string[]>()).Returns(new[] { TestEnvironment.ConstructRootedPath("App", "MyApp", "Hello.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.csx"), TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.sh"), TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.sh"), TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.ps1"), TestEnvironment.ConstructRootedPath("App", "MyApp", "DeployFailed.sh") });

            commandResult = new CommandResult("PowerShell.exe foo bar", 0, null);
            scriptEngine  = Substitute.For <IScriptEngine>();
            scriptEngine.Execute(Arg.Any <Script>(), Arg.Any <IVariables>(), Arg.Any <ICommandLineRunner>()).Returns(c => commandResult);
            scriptEngine.GetSupportedTypes().Returns(new[] { ScriptSyntax.CSharp, ScriptSyntax.PowerShell, ScriptSyntax.Bash });
            runner     = Substitute.For <ICommandLineRunner>();
            deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), new CalamariVariables());
            log        = new InMemoryLog();
        }
Exemple #28
0
        public void ShouldNotDeletePostDeployScriptAfterExecutionIfSpecialVariableIsSet()
        {
            var postDeployPs1 = TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.ps1");
            var postDeploySh  = TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.sh");

            deployment.Variables.Set(SpecialVariables.DeleteScriptsOnCleanup, false.ToString());
            var convention = CreateConvention("PostDeploy");

            convention.Install(deployment);
            scriptEngine.Received().Execute(Arg.Is <Script>(s => s.File == postDeployPs1), deployment.Variables, runner);
            scriptEngine.DidNotReceive().Execute(Arg.Is <Script>(s => s.File == postDeploySh), deployment.Variables, runner);
            fileSystem.DidNotReceive().DeleteFile(postDeployPs1, Arg.Any <FailureOptions>());
            fileSystem.DidNotReceive().DeleteFile(postDeploySh, Arg.Any <FailureOptions>());
            log.StandardOut.Should().ContainMatch($"Found 2 PostDeploy scripts. Selected {postDeployPs1} based on OS preferential ordering: CSharp, PowerShell, Bash");
        }
        public void SetUp()
        {
            fileSystem = Substitute.For <ICalamariFileSystem>();
            fileSystem.EnumerateFiles(Arg.Any <string>(), Arg.Any <string[]>()).Returns(new[]
            {
                TestEnvironment.ConstructRootedPath("App", "MyApp", "Hello.ps1"),
                TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.ps1"),
                TestEnvironment.ConstructRootedPath("App", "MyApp", "Deploy.csx"),
                TestEnvironment.ConstructRootedPath("App", "MyApp", "PreDeploy.ps1"),
                TestEnvironment.ConstructRootedPath("App", "MyApp", "PostDeploy.ps1")
            });

            commandResult = new CommandResult("PowerShell.exe foo bar", 0, null);
            scriptEngine  = Substitute.For <IScriptEngine>();
            scriptEngine.Execute(Arg.Any <string>(), Arg.Any <CalamariVariableDictionary>(), Arg.Any <ICommandLineRunner>()).Returns(c => commandResult);
            scriptEngine.GetSupportedExtensions().Returns(new[] { "csx", "ps1" });
            runner     = Substitute.For <ICommandLineRunner>();
            deployment = new RunningDeployment(TestEnvironment.ConstructRootedPath("Packages"), new CalamariVariableDictionary());
        }