Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run EndToEnd tests on every commit #153

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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