Пример #1
0
        public void PushAndDeployApps(string name, string repoName,
                                      string repoUrl, string repoCloneUrl,
                                      string defaultBranchName, string verificationText,
                                      HttpStatusCode expectedResponseCode, bool skip, string verificationLogText = null)
        {
            if (!skip)
            {
                string randomTestName = KuduUtils.GetRandomWebsiteName(repoName);
                using (var repo = Git.Clone(randomTestName, repoCloneUrl))
                {
                    ApplicationManager.Run(randomTestName, appManager =>
                    {
                        // Act
                        appManager.GitDeploy(repo.PhysicalPath, defaultBranchName);
                        var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                        // Assert
                        Assert.Equal(1, results.Count);
                        Assert.Equal(DeployStatus.Success, results[0].Status);
                        KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText, expectedResponseCode);
                        if (!String.IsNullOrEmpty(verificationLogText.Trim()))
                        {
                            KuduAssert.VerifyLogOutput(appManager, results[0].Id, verificationLogText.Trim());
                        }
                    });
                }
                Debug.Write(String.Format("Test completed: {0}\n", name));
            }
            else
            {
                Debug.Write(String.Format("Test skipped: {0}\n", name));
            }
        }
Пример #2
0
        public void WarningsAsErrors()
        {
            // Arrange
            string repositoryName = "WarningsAsErrors";
            string appName        = KuduUtils.GetRandomWebsiteName("WarningsAsErrors");
            string cloneUrl       = "https://github.com/KuduApps/WarningsAsErrors.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    Assert.Null(results[0].LastSuccessEndTime);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "Warning as Error: The variable 'x' is declared but never used");
                    Assert.True(deployResult.GitTrace.Contains("Warning as Error: The variable 'x' is declared but never used"));
                    Assert.True(deployResult.GitTrace.Contains("Error - Changes committed to remote repository but your website not updated."));
                });
            }
        }
Пример #3
0
        private void VerifyDeploymentConfiguration(string siteName, string targetProject, string expectedText, DeployStatus expectedStatus = DeployStatus.Success, string expectedLog = null)
        {
            string name     = KuduUtils.GetRandomWebsiteName(siteName);
            string cloneUrl = "https://github.com/KuduApps/SpecificDeploymentConfiguration.git";

            using (var repo = Git.Clone(name, cloneUrl))
            {
                ApplicationManager.Run(name, appManager =>
                {
                    string deploymentFile = Path.Combine(repo.PhysicalPath, @".deployment");
                    File.WriteAllText(deploymentFile, String.Format(@"[config]
project = {0}", targetProject));
                    Git.Commit(name, "Updated configuration");

                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(expectedStatus, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, expectedText);
                    if (!String.IsNullOrEmpty(expectedLog))
                    {
                        KuduAssert.VerifyLogOutput(appManager, results[0].Id, expectedLog);
                    }
                });
            }
        }
        public void PushSimpleWapWithFailingCustomDeploymentScript()
        {
            // Arrange
            string repositoryName = "WapWithFailingCustomDeploymentScript";
            string appName        = KuduUtils.GetRandomWebsiteName("WapWithFailingCustomDeploymentScript");
            string cloneUrl       = "https://github.com/KuduApps/CustomBuildScript.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                repo.WriteFile(".deployment", @"
[config]
command = deploy.cmd");
                repo.WriteFile("deploy.cmd", "bogus");
                Git.Commit(repo.PhysicalPath, "Updated the deploy file.");

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    GitDeploymentResult deployResult = appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, ">bogus");
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "'bogus' is not recognized as an internal or external command");
                });
            }
        }
Пример #5
0
        public void PostDeploymentActionWhichFailsShouldFailDeployment()
        {
            string testName          = "PostDeploymentActionsShouldBeCalledOnSuccessfulPublish";
            string testLine1         = "test script 1 is running";
            string testLine2         = "test script 2 is running too";
            string failScriptCommand = "\n exit /b 1";

            using (new LatencyLogger(testName))
            {
                ApplicationManager.Run(testName, appManager =>
                {
                    using (var appRepository = Git.Clone("HelloKudu"))
                    {
                        TestTracer.Trace("Add action scripts, first script should fail, second script shouldn't run");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1 + failScriptCommand);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2);

                        TestTracer.Trace("Deploy test app");
                        appManager.GitDeploy(appRepository.PhysicalPath);

                        TestTracer.Trace("Verify results");
                        var deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Failed, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1);
                        KuduAssert.VerifyLogOutputWithUnexpected(appManager, deploymentResults[0].Id, testLine2);

                        TestTracer.Trace("Update action scripts, first script should succeed, second script should fail");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2 + failScriptCommand);

                        TestTracer.Trace("Deploy test app");
                        appManager.DeploymentManager.DeployAsync(null).Wait();

                        TestTracer.Trace("Verify results");
                        deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Failed, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1, testLine2);
                    }
                });
            }
        }
Пример #6
0
        public void PostDeploymentActionsShouldBeCalledOnSuccessfulDeployment()
        {
            string testName  = "PostDeploymentActionsShouldBeCalledOnSuccessfulDeployment";
            string testLine1 = "test script 1 is running";
            string testLine2 = "test script 2 is running too";

            const string testCommitIdPrefix   = @"SCM_COMMIT_ID = ";
            const string testCommitIdVariable = @"%SCM_COMMIT_ID%";

            using (new LatencyLogger(testName))
            {
                ApplicationManager.Run(testName, appManager =>
                {
                    using (var appRepository = Git.Clone("HelloKudu"))
                    {
                        TestTracer.Trace("Add action scripts");
                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_1.cmd",
                            @"@echo off
                              echo " + testLine1);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_2.bat",
                            @"@echo off
                              echo " + testLine2);

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_3.sh",
                            @"@echo off
                              echo fail if we try to run this
                              exit /b 1");

                        appManager.VfsManager.WriteAllText(
                            @"site\deployments\tools\PostDeploymentActions\test_script_4.cmd",
                            @"@echo off
                              echo " + testCommitIdPrefix + testCommitIdVariable);

                        TestTracer.Trace("Deploy test app");
                        appManager.GitDeploy(appRepository.PhysicalPath);

                        TestTracer.Trace("Verify results");
                        var deploymentResults = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                        Assert.Equal(1, deploymentResults.Count);
                        Assert.Equal(DeployStatus.Success, deploymentResults[0].Status);

                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testLine1, testLine2);
                        KuduAssert.VerifyLogOutput(appManager, deploymentResults[0].Id, testCommitIdPrefix + deploymentResults[0].Id);
                    }
                });
            }
        }
Пример #7
0
        //Common code
        internal static void PushAndDeployApps(string repoCloneUrl, string defaultBranchName, string verificationText,
                                               HttpStatusCode expectedResponseCode, string verificationLogText,
                                               DeployStatus expectedStatus = DeployStatus.Success, string resourcePath = "",
                                               string httpMethod           = "GET", string jsonPayload = "", bool deleteSCM = false)
        {
            using (new LatencyLogger("PushAndDeployApps - " + repoCloneUrl))
            {
                Uri uri;
                if (!Uri.TryCreate(repoCloneUrl, UriKind.Absolute, out uri))
                {
                    uri = null;
                }

                string randomTestName = uri != null?Path.GetFileNameWithoutExtension(repoCloneUrl) : repoCloneUrl;

                ApplicationManager.Run(randomTestName, appManager =>
                {
                    // Act
                    using (TestRepository testRepository = Git.Clone(randomTestName, uri != null ? repoCloneUrl : null))
                    {
                        using (new LatencyLogger("GitDeploy"))
                        {
                            appManager.GitDeploy(testRepository.PhysicalPath, defaultBranchName);
                        }
                    }
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(expectedStatus, results[0].Status);
                    var url = new Uri(new Uri(appManager.SiteUrl), resourcePath);
                    if (!String.IsNullOrEmpty(verificationText))
                    {
                        KuduAssert.VerifyUrl(url.ToString(), verificationText, expectedResponseCode, httpMethod, jsonPayload);
                    }
                    if (!String.IsNullOrEmpty(verificationLogText))
                    {
                        KuduAssert.VerifyLogOutput(appManager, results[0].Id, verificationLogText.Trim());
                    }
                    if (deleteSCM)
                    {
                        using (new LatencyLogger("SCMAndWebDelete"))
                        {
                            appManager.RepositoryManager.Delete(deleteWebRoot: false, ignoreErrors: false).Wait();
                        }
                    }
                });
            }
        }
Пример #8
0
        public async Task CustomDeploymentScriptShouldHaveDeploymentSetting()
        {
            // use a fresh guid so its impossible to accidently see the right output just by chance.
            var guidtext            = Guid.NewGuid().ToString();
            var unicodeText         = "酷度酷度";
            var normalVar           = "TESTED_VAR";
            var normalVarText       = "Settings Were Set Properly" + guidtext;
            var kuduSetVar          = "KUDU_SYNC_CMD";
            var kuduSetVarText      = "Fake Kudu Sync " + guidtext;
            var expectedLogFeedback = "Using custom deployment setting for {0} custom value is '{1}'.".FormatCurrentCulture(kuduSetVar, kuduSetVarText);

            string randomTestName = "CustomDeploymentScriptShouldHaveDeploymentSetting";
            await ApplicationManager.RunAsync(randomTestName, async appManager =>
            {
                appManager.SettingsManager.SetValue(normalVar, normalVarText).Wait();
                appManager.SettingsManager.SetValue(kuduSetVar, kuduSetVarText).Wait();

                // Act
                using (TestRepository testRepository = Git.Clone("CustomDeploymentSettingsTest"))
                {
                    appManager.GitDeploy(testRepository.PhysicalPath, "master");
                }
                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                // Assert
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);

                // Also validate custom script output supports unicode
                string[] expectedStrings =
                {
                    unicodeText,
                    normalVar + "=" + normalVarText,
                    kuduSetVar + "=" + kuduSetVarText,
                    expectedLogFeedback
                };
                KuduAssert.VerifyLogOutput(appManager, results[0].Id, expectedStrings);

                var ex = await Assert.ThrowsAsync <HttpUnsuccessfulRequestException>(() => appManager.DeploymentManager.GetDeploymentScriptAsync());
                Assert.Equal(HttpStatusCode.NotFound, ex.ResponseMessage.StatusCode);
                Assert.Contains("Operation only supported if not using a custom deployment script", ex.ResponseMessage.ExceptionMessage);
            });
        }
Пример #9
0
        public void CustomDeploymentScriptShouldHaveDeploymentSetting()
        {
            // use a fresh guid so its impossible to accidently see the right output just by chance.
            var guidtext            = Guid.NewGuid().ToString();
            var unicodeText         = "酷度酷度";
            var normalVar           = "TESTED_VAR";
            var normalVarText       = "Settings Were Set Properly" + guidtext;
            var kuduSetVar          = "KUDU_SYNC_CMD";
            var kuduSetVarText      = "Fake Kudu Sync " + guidtext;
            var expectedLogFeedback =
                KuduUtils.TestOriginalSiteBuilderFactory ?
                String.Empty :
                "Using custom deployment setting for {0} custom value is '{1}'.".FormatCurrentCulture(kuduSetVar, kuduSetVarText);

            string randomTestName = "CustomDeploymentScriptShouldHaveDeploymentSetting";

            ApplicationManager.Run(randomTestName, appManager =>
            {
                appManager.SettingsManager.SetValue(normalVar, normalVarText).Wait();
                appManager.SettingsManager.SetValue(kuduSetVar, kuduSetVarText).Wait();

                // Act
                using (TestRepository testRepository = Git.Clone("CustomDeploymentSettingsTest"))
                {
                    appManager.GitDeploy(testRepository.PhysicalPath, "master");
                }
                var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                // Assert
                Assert.Equal(1, results.Count);
                Assert.Equal(DeployStatus.Success, results[0].Status);

                // Also validate custom script output supports unicode
                string[] expectedStrings =
                {
                    unicodeText,
                    normalVar + "=" + normalVarText,
                    kuduSetVar + "=" + kuduSetVarText,
                    expectedLogFeedback
                };
                KuduAssert.VerifyLogOutput(appManager, results[0].Id, expectedStrings);
            });
        }
Пример #10
0
        private static void PushAndDeployApps(string name, string repoName, string repoCloneUrl, string defaultBranchName,
                                              string verificationText, HttpStatusCode expectedResponseCode, string verificationLogText)
        {
            TestRepository testRepository = null;

            string localRepo      = KuduUtils.GetCachedRepositoryPath(repoName);
            string randomTestName = KuduUtils.GetRandomWebsiteName(repoName);

            if (localRepo == null)
            {
                testRepository = Git.Clone(randomTestName, repoCloneUrl);
                localRepo      = testRepository.PhysicalPath;
            }

            try
            {
                ApplicationManager.Run(randomTestName, appManager =>
                {
                    // Act
                    appManager.GitDeploy(localRepo, defaultBranchName);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText, expectedResponseCode);
                    if (!String.IsNullOrEmpty(verificationLogText.Trim()))
                    {
                        KuduAssert.VerifyLogOutput(appManager, results[0].Id, verificationLogText.Trim());
                    }
                });
            }
            finally
            {
                if (testRepository != null)
                {
                    testRepository.Dispose();
                }
            }
        }
Пример #11
0
        public void PushRepositoryWithNoDeployableProjectsTreatsAsWebsite()
        {
            // Arrange
            string repositoryName = "PushRepositoryWithNoDeployableProjectsTreatsAsWebsite";
            string appName        = KuduUtils.GetRandomWebsiteName("PushNoDeployableProj");
            string cloneUrl       = "https://github.com/KuduApps/NoDeployableProjects.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "no deployable projects. Deploying files instead");
                });
            }
        }
Пример #12
0
        public void FailedNpmFailsDeployment()
        {
            string repositoryName = "FailedNpmFailsDeployment";
            string appName        = KuduUtils.GetRandomWebsiteName("FailedNpm");
            string cloneUrl       = "https://github.com/KuduApps/NpmSite.git";

            using (var repo = Git.Clone(repositoryName, cloneUrl))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Replace the express dependency with something that doesn't exist
                    repo.Replace("package.json", "express", "MadeUpKuduPackage");
                    Git.Commit(repo.PhysicalPath, "Added fake package to package.json");
                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    KuduAssert.VerifyLogOutput(appManager, results[0].Id, "'MadeUpKuduPackage' is not in the npm registry.");
                });
            }
        }
Пример #13
0
        public void DeploymentApis()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("DeploymentApis");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    Assert.Equal(1, results.Count);
                    var result = results[0];
                    Assert.Equal("Raquel Almeida", result.Author);
                    Assert.Equal("*****@*****.**", result.AuthorEmail);
                    Assert.True(result.Current);
                    Assert.Equal(DeployStatus.Success, result.Status);
                    Assert.NotNull(result.Url);
                    Assert.NotNull(result.LogUrl);
                    Assert.True(String.IsNullOrEmpty(result.Deployer));

                    ICredentials cred = appManager.DeploymentManager.Credentials;
                    KuduAssert.VerifyUrl(result.Url, cred);
                    KuduAssert.VerifyUrl(result.LogUrl, cred);

                    var resultAgain = appManager.DeploymentManager.GetResultAsync(result.Id).Result;
                    Assert.Equal("Raquel Almeida", resultAgain.Author);
                    Assert.Equal("*****@*****.**", resultAgain.AuthorEmail);
                    Assert.True(resultAgain.Current);
                    Assert.Equal(DeployStatus.Success, resultAgain.Status);
                    Assert.NotNull(resultAgain.Url);
                    Assert.NotNull(resultAgain.LogUrl);
                    KuduAssert.VerifyUrl(resultAgain.Url, cred);
                    KuduAssert.VerifyUrl(resultAgain.LogUrl, cred);

                    repo.WriteFile("HelloWorld.txt", "This is a test");
                    Git.Commit(repo.PhysicalPath, "Another commit");
                    appManager.GitDeploy(repo.PhysicalPath);
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(2, results.Count);
                    string oldId = results[1].Id;

                    // Delete one
                    appManager.DeploymentManager.DeleteAsync(oldId).Wait();

                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                    Assert.Equal(1, results.Count);
                    Assert.NotEqual(oldId, results[0].Id);

                    result = results[0];

                    // Redeploy
                    appManager.DeploymentManager.DeployAsync(result.Id).Wait();

                    // Clean deploy
                    appManager.DeploymentManager.DeployAsync(result.Id, clean: true).Wait();

                    var entries = appManager.DeploymentManager.GetLogEntriesAsync(result.Id).Result.ToList();

                    Assert.True(entries.Count > 0);

                    // First entry is always null
                    Assert.Null(entries[0].DetailsUrl);

                    var entryWithDetails = entries.First(e => e.DetailsUrl != null);

                    var nested = appManager.DeploymentManager.GetLogEntryDetailsAsync(result.Id, entryWithDetails.Id).Result.ToList();

                    Assert.True(nested.Count > 0);

                    KuduAssert.VerifyLogOutput(appManager, result.Id, "Cleaning git repository");

                    // Can't delete the active one
                    var ex = KuduAssert.ThrowsUnwrapped <HttpRequestException>(() => appManager.DeploymentManager.DeleteAsync(result.Id).Wait());
                    Assert.Equal("Response status code does not indicate success: 409 (Conflict).", ex.Message);
                });
            }
        }