public void WebsiteWithIISExpressWorks()
        {
            // Arrange
            string repositoryName = "WebsiteWithIISExpressWorks";
            string appName        = KuduUtils.GetRandomWebsiteName("WebsiteWithIISExpressWorks");
            string cloneUrl       = "https://github.com/KuduApps/waws.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.VerifyUrl(appManager.SiteUrl, "Home");
                });
            }
        }
        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");
                });
            }
        }
        public void WapBuildsReleaseMode()
        {
            // Arrange
            string repositoryName = "WapBuildsReleaseMode";
            string appName        = KuduUtils.GetRandomWebsiteName("WapBuildsRelease");
            string cloneUrl       = "https://github.com/KuduApps/ConditionalCompilation.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.VerifyUrl(appManager.SiteUrl, null, "RELEASE MODE", "Context.IsDebuggingEnabled: False");
                });
            }
        }
        public void PushSimpleRepoShouldDeploy()
        {
            // Arrange
            string repositoryName   = "Bakery10";
            string appName          = KuduUtils.GetRandomWebsiteName("PushSimpleRepo");
            string verificationText = "Welcome to Fourth Coffee!";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                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.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }
        public void PushRepoWithProjectAndNoSolutionShouldDeploy()
        {
            // Arrange
            string repositoryName   = "Mvc3Application_NoSolution";
            string appName          = KuduUtils.GetRandomWebsiteName("PushRepoWithProjNoSln");
            string verificationText = "Kudu Deployment Testing: Mvc3Application_NoSolution";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                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.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }
        public void PushingConfiguredBranch()
        {
            string repositoryName = "PushingConfiguredBranch";
            string appName        = KuduUtils.GetRandomWebsiteName("PushingConfiguredBranch");
            string cloneUrl       = "https://github.com/KuduApps/RepoWithMultipleBranches.git";

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

                    // Assert
                    Assert.Equal(1, results.Count);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Test branch");
                });
            }
        }
Example #7
0
        public void SetGetValue()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("SetValue");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.SettingsManager.SetValue("x", "1").Wait();
                    appManager.SettingsManager.SetValueLegacy("y", "2").Wait();

                    // Assert
                    string result = appManager.SettingsManager.GetValue("x").Result;
                    Assert.Equal("1", result);
                    result = appManager.SettingsManager.GetValue("y").Result;
                    Assert.Equal("2", result);
                });
            }
        }
Example #8
0
        public void TestPositiveMatch()
        {
            // Arrange
            string repositoryName = "VersionPinnedNodeJsApp";
            string appName        = KuduUtils.GetRandomWebsiteName("VersionPinnedNodeJsApp");
            string cloneUrl       = "https://github.com/KuduApps/VersionPinnedNodeJsApp.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.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "v0.8.2");
                });
            }
        }
        public void AppNameWithSignalRWorks()
        {
            // Arrange
            string repositoryName   = "Mvc3Application";
            string appName          = KuduUtils.GetRandomWebsiteName("signalroverflow");
            string verificationText = "Welcome to ASP.NET MVC!";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                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.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }
        public void PushShouldOverwriteModifiedFilesInRepo()
        {
            // Arrange
            string repositoryName   = "Mvc3Application";
            string appName          = KuduUtils.GetRandomWebsiteName("PushOverwriteModified");
            string verificationText = "Welcome to ASP.NET MVC!";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);

                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText);

                    appManager.ProjectSystem.WriteAllText("Views/Home/Index.cshtml", "Hello world!");

                    // Sleep a little since it's a remote call
                    Thread.Sleep(500);

                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Hello world!");

                    // Make an unrelated change (newline to the end of web.config)
                    repo.AppendFile(@"Mvc3Application\Web.config", "\n");

                    Git.Commit(repo.PhysicalPath, "This is a test");

                    appManager.GitDeploy(repo.PhysicalPath);

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

                    // Assert
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }
Example #11
0
        public void TestLogStreamBasic()
        {
            string repoName     = "LogTester";
            string repoCloneUrl = "https://github.com/KuduApps/LogTester.git";
            string appName      = KuduUtils.GetRandomWebsiteName("TestLogStreamBasic");

            string localRepo = GetRepositoryPath(repoName, repoCloneUrl, appName);

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                appManager.GitDeploy(localRepo);

                CreateLogDirectory(appManager.SiteUrl, @"LogFiles");

                using (var waitHandle = new LogStreamWaitHandle(appManager.LogStreamManager.GetStream().Result))
                {
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!String.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);

                    string content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.txt", content);
                    line = waitHandle.WaitNextLine(10000);
                    Assert.Equal(content, line);

                    content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.log", content);
                    line = waitHandle.WaitNextLine(10000);
                    Assert.Equal(content, line);

                    // write to xml file, we should not get any live stream
                    content = Guid.NewGuid().ToString();
                    WriteLogText(appManager.SiteUrl, @"LogFiles\temp.xml", content);
                    line = waitHandle.WaitNextLine(1000);
                    Assert.Null(line);
                }
            });
        }
Example #12
0
        public void PushRepoWithMultipleProjectsShouldDeploy()
        {
            // Arrange
            string repositoryName   = "Mvc3Application";
            string appName          = KuduUtils.GetRandomWebsiteName("PushMultiProjects");
            string verificationText = "Welcome to ASP.NET MVC! - Change1";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                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);
                    Assert.NotNull(results[0].LastSuccessEndTime);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, verificationText);
                });
            }
        }
        public void RedeployNodeSite()
        {
            string repositoryName = "RedeployNodeSite";
            string appName        = KuduUtils.GetRandomWebsiteName("RedeployNodeSite");
            string cloneUrl       = "https://github.com/KuduApps/NodeHelloWorldNoConfig.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);

                    string id = results[0].Id;

                    repo.Replace("server.js", "world", "world2");
                    Git.Commit(repo.PhysicalPath, "Made a small change");

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

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

                    appManager.DeploymentManager.DeployAsync(id).Wait();
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    Assert.Equal(DeployStatus.Success, results[1].Status);
                });
            }
        }
Example #14
0
        public void NSimpleDeployments()
        {
            string repositoryName = "HelloKudu";
            string cloneUrl       = "https://github.com/KuduApps/HelloKudu.git";

            using (Git.Clone(repositoryName, cloneUrl))
            {
                for (int i = 0; i < 5; i++)
                {
                    string applicationName = KuduUtils.GetRandomWebsiteName(repositoryName + i);
                    ApplicationManager.Run(applicationName, appManager =>
                    {
                        // Act
                        appManager.GitDeploy(repositoryName);
                        var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

                        // Assert
                        Assert.Equal(1, results.Count);
                        Assert.Equal(DeployStatus.Success, results[0].Status);
                        KuduAssert.VerifyUrl(appManager.SiteUrl, "Hello Kudu");
                    });
                }
            }
        }
Example #15
0
        public void DeploymentManagerExtensibility()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("DeploymentApis");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    var handler = new FakeMessageHandler()
                    {
                        InnerHandler = new HttpClientHandler()
                    };

                    var manager         = new RemoteDeploymentManager(appManager.DeploymentManager.ServiceUrl, handler);
                    manager.Credentials = appManager.DeploymentManager.Credentials;
                    var results         = manager.GetResultsAsync().Result.ToList();

                    Assert.Equal(0, results.Count);
                    Assert.NotNull(handler.Url);
                });
            }
        }
Example #16
0
        public void NodeHelloWorldNoConfig()
        {
            string repositoryName = "NodeHelloWorldNoConfig";
            string appName        = KuduUtils.GetRandomWebsiteName("NodeConfig");
            string cloneUrl       = "https://github.com/KuduApps/NodeHelloWorldNoConfig.git";

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

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

                    // Make sure a web.config file got created at deployment time
                    Assert.True(files.Contains("web.config"));
                });
            }
        }
Example #17
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.");
                });
            }
        }
Example #18
0
        public void CloneFromEmptyRepoAndPushShouldDeploy()
        {
            string repositoryName = "CloneFromEmptyRepoAndPushShouldDeploy";
            string appName        = KuduUtils.GetRandomWebsiteName("CloneEmptyAndPush");

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                using (var repo = Git.Clone(repositoryName, appManager.GitUrl, createDirectory: true))
                {
                    // Add a file
                    repo.WriteFile("hello.txt", "Wow");
                    Git.Commit(repo.PhysicalPath, "Added hello.txt");
                    string helloUrl = appManager.SiteUrl + "/hello.txt";

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

                    // Assert
                    Assert.Equal(1, results.Count);
                    KuduAssert.VerifyUrl(helloUrl, "Wow");
                }
            });
        }
Example #19
0
        public void GetAllValues()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("SetValue");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.SettingsManager.SetValue("x", "1").Wait();
                    appManager.SettingsManager.SetValue("y", "2").Wait();
                    appManager.SettingsManager.SetValue("z", "3").Wait();

                    // Assert
                    NameValueCollection results = appManager.SettingsManager.GetValues().Result;

                    Assert.Equal("1", results["x"]);
                    Assert.Equal("2", results["y"]);
                    Assert.Equal("3", results["z"]);
                });
            }
        }
Example #20
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);
                });
            }
        }
Example #21
0
        public void GetResultsWithMaxItemsAndExcludeFailed()
        {
            // Arrange
            string repositoryName = "Mvc3Application";
            string appName        = KuduUtils.GetRandomWebsiteName("RsltMaxItemXcldFailed");

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    string homeControllerPath = Path.Combine(repo.PhysicalPath, @"Mvc3Application\Controllers\HomeController.cs");

                    // Act, Initial Commit
                    appManager.GitDeploy(repo.PhysicalPath);

                    // Assert
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET MVC! - Change1");

                    // Act, Change 2
                    File.WriteAllText(homeControllerPath, File.ReadAllText(homeControllerPath).Replace(" - Change1", " - Change2"));
                    Git.Commit(repo.PhysicalPath, "Change 2!");
                    appManager.GitDeploy(repo.PhysicalPath);

                    // Assert
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    Assert.Equal(DeployStatus.Success, results[1].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET MVC! - Change2");

                    // Act, Invalid Change build-break change and commit
                    File.WriteAllText(homeControllerPath, File.ReadAllText(homeControllerPath).Replace("Index()", "Index;"));
                    Git.Commit(repo.PhysicalPath, "Invalid Change!");
                    appManager.GitDeploy(repo.PhysicalPath);

                    // Assert
                    results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    Assert.Equal(3, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    Assert.Equal(DeployStatus.Success, results[1].Status);
                    Assert.Equal(DeployStatus.Success, results[2].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl, "Welcome to ASP.NET MVC! - Change2");

                    // Test maxItems = 2
                    results = appManager.DeploymentManager.GetResultsAsync(maxItems: 2).Result.ToList();
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Failed, results[0].Status);
                    Assert.Equal(DeployStatus.Success, results[1].Status);

                    // Test excludeFailed = true
                    results = appManager.DeploymentManager.GetResultsAsync(excludeFailed: true).Result.ToList();
                    Assert.Equal(2, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    Assert.Equal(DeployStatus.Success, results[1].Status);

                    // Test maxItems = 1, excludeFailed = true
                    results = appManager.DeploymentManager.GetResultsAsync(maxItems: 1, excludeFailed: true).Result.ToList();
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    Assert.True(results[0].Current);
                });
            }
        }
        public void CustomNodeScript()
        {
            string repositoryName = "CustomNodeScript";
            string appName        = KuduUtils.GetRandomWebsiteName("CustomNodeScript");
            string webConfig      = @"
<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <system.webServer>         
      <handlers>
           <add name=""iisnode"" path=""server.js"" verb=""*"" modules=""iisnode""/>
     </handlers>
      <rewrite>
           <rules>
                <rule name=""StaticContent"">
                     <action type=""Rewrite"" url=""public{REQUEST_URI}""/>
                </rule>
                <rule name=""DynamicContent"">
                     <conditions>
                          <add input=""{REQUEST_FILENAME}"" matchType=""IsFile"" negate=""True""/>
                     </conditions>
                     <action type=""Rewrite"" url=""server.js""/>
                </rule>
           </rules>
      </rewrite>
    <iisnode 
      nodeProcessCommandLine=""&quot;%programfiles(x86)%\nodejs\node.exe&quot;""
      debuggingEnabled=""false""
      logDirectory=""..\..\LogFiles\nodejs"" 
      watchedFiles=""*.js;iisnode.yml;node_modules\*;views\*.jade;views\*.ejb;routes\*.js"" />
   </system.webServer>
 </configuration>";

            var path = Git.GetRepositoryPath(repositoryName);

            using (var repo = Git.Init(path))
            {
                repo.WriteFile("build.js", String.Format(@"var fs = require('fs');
console.log('Creating server.js on the fly!');
console.log('target is ' + process.env.DEPLOYMENT_TARGET);
fs.writeFileSync(process.env.DEPLOYMENT_TARGET + '\server.js', ""var http = require('http'); http.createServer(function (req, res) {{ res.writeHead(200, {{'Content-Type': 'text/html'}}); res.end('Hello, world! [helloworld sample; iisnode version is ' + process.env.IISNODE_VERSION + ', node version is ' + process.version + ']'); }}).listen(process.env.PORT);"");
console.log('Done!');", webConfig));
                repo.WriteFile(".deployment", @"
[config]
command = node build.js
");
                repo.WriteFile("web.config", webConfig);

                Git.Commit(repo.PhysicalPath, "Added build.js");

                ApplicationManager.Run(appName, appManager =>
                {
                    // Act
                    appManager.GitDeploy(repo.PhysicalPath);
                    var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();
                    var files   = appManager.ProjectSystem.GetProject().Files.ToList();

                    // Assert
                    Assert.Equal(1, results.Count);
                    Assert.Equal(DeployStatus.Success, results[0].Status);
                    KuduAssert.VerifyUrl(appManager.SiteUrl);
                });
            }
        }
Example #23
0
        public void TestLogStreamSubFolder()
        {
            string appName      = KuduUtils.GetRandomWebsiteName("TestLogStreamFilter");
            string repoName     = "LogTester";
            string repoCloneUrl = "https://github.com/KuduApps/LogTester.git";

            TestRepository testRepository = null;
            string         localRepo      = KuduUtils.GetCachedRepositoryPath(repoName);

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

            ApplicationManager.Run(appName, appManager =>
            {
                // Act
                appManager.GitDeploy(localRepo);
                List <string> logFiles = new List <string>();
                List <LogStreamWaitHandle> waitHandles = new List <LogStreamWaitHandle>();
                for (int i = 0; i < 2; ++i)
                {
                    logFiles.Add(@"LogFiles\Folder" + i + "\\temp.txt");
                    //Create the directory
                    CreateLogDirectory(appManager.SiteUrl, @"LogFiles\Folder" + i);
                    RemoteLogStreamManager mgr = appManager.CreateLogStreamManager("folder" + i);
                    var waitHandle             = new LogStreamWaitHandle(mgr.GetStream().Result);
                    string line = waitHandle.WaitNextLine(10000);
                    Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);
                    waitHandles.Add(waitHandle);
                }

                using (LogStreamWaitHandle waitHandle = new LogStreamWaitHandle(appManager.LogStreamManager.GetStream().Result))
                {
                    try
                    {
                        string line = waitHandle.WaitNextLine(10000);
                        Assert.True(!string.IsNullOrEmpty(line) && line.Contains("Welcome"), "check welcome message: " + line);

                        // write to folder0, we should not get any live stream for folder1 listener
                        string content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[0], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);

                        // write to folder1, we should not get any live stream for folder0 listener
                        content = Guid.NewGuid().ToString();
                        WriteLogText(appManager.SiteUrl, logFiles[1], content);
                        line = waitHandle.WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[1].WaitNextLine(10000);
                        Assert.Equal(content, line);
                        line = waitHandles[0].WaitNextLine(1000);
                        Assert.True(line == null, "no more message: " + line);
                    }
                    finally
                    {
                        waitHandles[0].Dispose();
                        waitHandles[1].Dispose();
                    }
                }
            });
        }