Skip to content

Commit

Permalink
Run EndToEnd tests on every commit
Browse files Browse the repository at this point in the history
  • Loading branch information
andymac4182 committed Sep 29, 2020
1 parent 08ab7bd commit 27518b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Build.Docker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ function Execute-Tests
{
& dotnet test ./test/SeqCli.Tests/SeqCli.Tests.csproj -c Release /p:Configuration=Release /p:Platform=x64 /p:VersionPrefix=$version
if ($LASTEXITCODE -ne 0) { exit 1 }

cd ./test/SeqCli.EndToEnd/
docker pull datalust/seq:latest
$env:ENDTOEND_USE_DOCKER_SEQ="Y"
& dotnet run
if ($LASTEXITCODE -ne 0) { exit 1 }
cd ../..
}

function Build-DockerImage
Expand Down
4 changes: 3 additions & 1 deletion test/SeqCli.EndToEnd/SeqCli.EndToEnd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" />
<PackageReference Include="Seq.Api" Version="5.1.1" />
</ItemGroup>
<ItemGroup>
<None Update="Data\*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SeqCli\SeqCli.csproj" />
</ItemGroup>
</Project>
25 changes: 24 additions & 1 deletion test/SeqCli.EndToEnd/Support/CaptiveProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace SeqCli.EndToEnd.Support
public sealed class CaptiveProcess : ITestProcess, IDisposable
{
readonly bool _captureOutput;
readonly string _stopCommandFullExePath;
readonly string _stopCommandArgs;
readonly Process _process;
readonly ManualResetEvent _outputComplete = new ManualResetEvent(false);
readonly ManualResetEvent _errorComplete = new ManualResetEvent(false);
Expand All @@ -20,10 +22,14 @@ public CaptiveProcess(
string fullExePath,
string args = null,
IDictionary<string, string> environment = null,
bool captureOutput = true)
bool captureOutput = true,
string stopCommandFullExePath = null,
string stopCommandArgs = null)
{
if (fullExePath == null) throw new ArgumentNullException(nameof(fullExePath));
_captureOutput = captureOutput;
_stopCommandFullExePath = stopCommandFullExePath;
_stopCommandArgs = stopCommandArgs;

var startInfo = new ProcessStartInfo
{
Expand Down Expand Up @@ -109,6 +115,23 @@ public void Dispose()
{
_process.Kill();
WaitForExit();
if (_stopCommandFullExePath != null)
{
var stopCommandStartInfo = new ProcessStartInfo
{
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
ErrorDialog = false,
FileName = _stopCommandFullExePath,
Arguments = _stopCommandArgs ?? ""
};

using var stopCommandProcess = Process.Start(stopCommandStartInfo);
stopCommandProcess?.WaitForExit();
}
}
catch
{
Expand Down
9 changes: 7 additions & 2 deletions test/SeqCli.EndToEnd/Support/TestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace SeqCli.EndToEnd.Support
{
public class TestConfiguration
{
public string ServerListenUrl { get; } = "http://localhost:9989";
public int ServerListenPort { get; } = 9989;

public string ServerListenUrl => $"http://localhost:{ServerListenPort}";

string EquivalentBaseDirectory { get; } = AppDomain.CurrentDomain.BaseDirectory
.Replace(Path.Combine("test", "SeqCli.EndToEnd"), Path.Combine("src", "SeqCli"));
Expand All @@ -30,7 +32,10 @@ public CaptiveProcess SpawnServerProcess(string storagePath)
if (storagePath == null) throw new ArgumentNullException(nameof(storagePath));

var commandWithArgs = $"run --listen=\"{ServerListenUrl}\" --storage=\"{storagePath}\"";

if (Environment.GetEnvironmentVariable("ENDTOEND_USE_DOCKER_SEQ") == "Y")
{
return new CaptiveProcess("docker", $"run --name seq -it --rm -e ACCEPT_EULA=Y -p {ServerListenPort}:80 datalust/seq:latest", stopCommandFullExePath: "docker", stopCommandArgs: "stop seq");
}
return new CaptiveProcess("seq", commandWithArgs);
}
}
Expand Down

0 comments on commit 27518b8

Please sign in to comment.