Skip to content

Commit

Permalink
Refactoring test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelsa committed Feb 27, 2012
1 parent f862a86 commit cefb6c1
Show file tree
Hide file tree
Showing 22 changed files with 858 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Kudu.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
[assembly: AssemblyDescription("Core APIs for Kudu.")]
[assembly: AssemblyProduct("Kudu.Core")]
[assembly: InternalsVisibleTo("Kudu.Core.Test")]
[assembly: InternalsVisibleTo("Kudu.FunctionalTests")]
[assembly: InternalsVisibleTo("Kudu.TestHarness")]
2 changes: 1 addition & 1 deletion Kudu.FunctionalTests/DeploymentManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using System.Net.Http;
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
using Xunit;

namespace Kudu.FunctionalTests
Expand Down
4 changes: 1 addition & 3 deletions Kudu.FunctionalTests/GitDeploymentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.Web.Infrastructure;
using Kudu.TestHarness;
using Xunit;
using Xunit.Extensions;

Expand Down
5 changes: 2 additions & 3 deletions Kudu.FunctionalTests/GitRepositoryManagementTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
using Xunit;

namespace Kudu.FunctionalTests
Expand All @@ -24,7 +23,7 @@ public void PushSimpleRepoShouldDeploy()
ApplicationManager.Run(appName, appManager =>
{
// Act
appManager.GitDeploy(repo.PhysicalPath);
appManager.GitDeploy(repo.PhysicalPath);
var results = appManager.DeploymentManager.GetResultsAsync().Result.ToList();

// Assert
Expand Down
3 changes: 1 addition & 2 deletions Kudu.FunctionalTests/GitStabilityTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Kudu.Core.Deployment;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;
using Xunit;

namespace Kudu.FunctionalTests
Expand Down
30 changes: 9 additions & 21 deletions Kudu.FunctionalTests/Kudu.FunctionalTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CsvHelper">
<HintPath>..\packages\CsvHelper.1.1.2\lib\net20\CsvHelper.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Json, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\JsonValue.0.6.0\lib\40\Microsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Net.Http.Formatting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\HttpClient.0.6.0\lib\40\Microsoft.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Server.Common, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\JsonValue.0.6.0\lib\40\Microsoft.Server.Common.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Administration, Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -60,7 +51,7 @@
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Net.Http">
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\HttpClient.0.6.0\lib\40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.ServiceModel" />
Expand All @@ -85,17 +76,6 @@
<Compile Include="DeploymentManagerTests.cs" />
<Compile Include="GitRepositoryManagementTests.cs" />
<Compile Include="GitStabilityTests.cs" />
<Compile Include="Infrastructure\GitTestConfig.cs" />
<Compile Include="Infrastructure\ApplicationManager.cs" />
<Compile Include="Infrastructure\ApplicationManagerExtensions.cs" />
<Compile Include="Infrastructure\Git.cs" />
<Compile Include="Infrastructure\KuduAssert.cs" />
<Compile Include="Infrastructure\PathHelper.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Infrastructure\TestRepository.cs" />
<Compile Include="Infrastructure\TestRepositoryExtensions.cs" />
<Compile Include="Infrastructure\Utils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GitDeploymentTests.cs" />
</ItemGroup>
Expand Down Expand Up @@ -128,6 +108,14 @@
<Project>{D5669C1D-3408-4CEE-8C1B-D86D03D27EE2}</Project>
<Name>Kudu.SiteManagement</Name>
</ProjectReference>
<ProjectReference Include="..\Kudu.TestHarness\Kudu.TestHarness.csproj">
<Project>{ACF3450A-8062-48D5-9C9D-8486261F290F}</Project>
<Name>Kudu.TestHarness</Name>
</ProjectReference>
<ProjectReference Include="..\Kudu.Web\Kudu.Web.csproj">
<Project>{B0265397-6FCD-4C67-8785-3272D8C1AD79}</Project>
<Name>Kudu.Web</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
2 changes: 0 additions & 2 deletions Kudu.FunctionalTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CsvHelper" version="1.1.2" />
<package id="DotNetZip" version="1.9.1.8" />
<package id="HttpClient" version="0.6.0" />
<package id="JsonValue" version="0.6.0" />
<package id="xunit" version="1.9.0.1566" />
Expand Down
6 changes: 3 additions & 3 deletions Kudu.Performance/Kudu.Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Kudu.FunctionalTests\Kudu.FunctionalTests.csproj">
<Project>{AB93801E-467D-4450-8951-60AE5A51CF4F}</Project>
<Name>Kudu.FunctionalTests</Name>
<ProjectReference Include="..\Kudu.TestHarness\Kudu.TestHarness.csproj">
<Project>{ACF3450A-8062-48D5-9C9D-8486261F290F}</Project>
<Name>Kudu.TestHarness</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Kudu.Performance/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using Kudu.FunctionalTests.Infrastructure;
using Kudu.TestHarness;

namespace Kudu.Performance
{
Expand Down
153 changes: 153 additions & 0 deletions Kudu.TestHarness/ApplicationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using Kudu.Client.Deployment;
using Kudu.Client.Editor;
using Kudu.Core.SourceControl;
using Kudu.SiteManagement;
using Kudu.Web.Infrastructure;

namespace Kudu.TestHarness
{
public class ApplicationManager
{
private readonly ISiteManager _siteManager;
private readonly Site _site;
private readonly string _appName;

private ApplicationManager(ISiteManager siteManager, Site site, string appName)
{
_siteManager = siteManager;
_site = site;
_appName = appName;
}

public string SiteUrl
{
get;
private set;
}

public string ServiceUrl
{
get;
private set;
}

public RemoteDeploymentManager DeploymentManager
{
get;
private set;
}

public RemoteProjectSystem ProjectSystem
{
get;
private set;
}

public string GitUrl
{
get
{
return GetCloneUrl(_site, RepositoryType.Git);
}
}

public string HgUrl
{
get
{
return GetCloneUrl(_site, RepositoryType.Mercurial);
}
}

private void Delete()
{
_siteManager.DeleteSite(_appName);
}

public static void Run(string applicationName, Action<ApplicationManager> action)
{
var appManager = CreateApplication(applicationName);
var dumpPath = Path.Combine(PathHelper.TestResultsPath, applicationName + ".zip");
try
{
action(appManager);

appManager.DownloadDump(dumpPath);

appManager.Delete();
}
catch (Exception ex)
{
appManager.DownloadDump(dumpPath);

Debug.WriteLine(ex.Message);
throw;
}
}

private void DownloadDump(string path)
{
try
{
Directory.CreateDirectory(Path.GetDirectoryName(path));

var client = new HttpClient();
var result = client.GetAsync(ServiceUrl + "diag").Result;
if (result.IsSuccessStatusCode)
{
using (Stream stream = result.Content.ReadAsStreamAsync().Result)
{
using (FileStream fs = File.OpenWrite(path))
{
stream.CopyTo(fs);
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine("Failed to download dump");
Debug.WriteLine(ex.GetBaseException().Message);
}
}

public static ApplicationManager CreateApplication(string applicationName)
{
var pathResolver = new DefaultPathResolver(PathHelper.ServiceSitePath, PathHelper.SitesPath);
var siteManager = GetSiteManager(pathResolver);

try
{
siteManager.DeleteSite(applicationName);
}
catch (System.ServiceModel.EndpointNotFoundException)
{

}

Site site = siteManager.CreateSite(applicationName);

return new ApplicationManager(siteManager, site, applicationName)
{
SiteUrl = site.SiteUrl,
ServiceUrl = site.ServiceUrl,
DeploymentManager = new RemoteDeploymentManager(site.ServiceUrl + "deployments"),
ProjectSystem = new RemoteProjectSystem(site.ServiceUrl + "live/files")
};
}

private string GetCloneUrl(Site site, Kudu.Core.SourceControl.RepositoryType type)
{
return site.ServiceUrl + (type == RepositoryType.Git ? "git" : "hg");
}

private static SiteManager GetSiteManager(DefaultPathResolver pathResolver)
{
return new SiteManager(pathResolver);
}
}
}
Loading

0 comments on commit cefb6c1

Please sign in to comment.