From 10797cc962b1bf741455c5b4330b9da6dd91ef62 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 29 Apr 2024 13:44:50 +1000 Subject: [PATCH 1/2] Launch configurations for local executable vs Docker/latest vs Docker/preview --- test/SeqCli.EndToEnd/Args.cs | 34 +++++++++++-------- .../Support/CliCommandRunner.cs | 10 ++---- ...nseCliSetupTestCase.cs => LicenseSetup.cs} | 9 ++--- .../Support/TestConfiguration.cs | 19 ++++------- 4 files changed, 30 insertions(+), 42 deletions(-) rename test/SeqCli.EndToEnd/Support/{LicenseCliSetupTestCase.cs => LicenseSetup.cs} (82%) diff --git a/test/SeqCli.EndToEnd/Args.cs b/test/SeqCli.EndToEnd/Args.cs index 258e17f8..4e1701ea 100644 --- a/test/SeqCli.EndToEnd/Args.cs +++ b/test/SeqCli.EndToEnd/Args.cs @@ -1,26 +1,32 @@ -using System.Linq; +using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Text.RegularExpressions; +#nullable enable + namespace SeqCli.EndToEnd; -public class Args +public class Args(params string[] args) { - readonly string[] _args; - - public Args(params string[] args) - { - _args = args; - } - - public Regex[] TestCases() => _args + public Regex[] TestCases() => args .Where(arg => !arg.StartsWith("--")) .Select(ToArgRegex) .ToArray(); // Simple replacement so `Events.*` becomes `Events\..*` - static Regex ToArgRegex(string arg) => new Regex(arg.Replace(".", "\\.").Replace("*", ".*")); + static Regex ToArgRegex(string arg) => new(arg.Replace(".", "\\.").Replace("*", ".*")); - public bool Multiuser() => _args.Any(a => a == "--license-certificate-stdin"); + public bool Multiuser() => args.Any(a => a == "--license-certificate-stdin"); - public bool UseDockerSeq() => _args.Any(a => a == "--docker-server"); -} \ No newline at end of file + public bool UseDockerSeq([NotNullWhen(true)] out string? imageTag) + { + if (args.Any(a => a == "--docker-server")) + { + imageTag = args.Any(a => a == "--pre") ? "preview" : "latest"; + return true; + } + + imageTag = null; + return false; + } +} diff --git a/test/SeqCli.EndToEnd/Support/CliCommandRunner.cs b/test/SeqCli.EndToEnd/Support/CliCommandRunner.cs index f17e6335..1955d913 100644 --- a/test/SeqCli.EndToEnd/Support/CliCommandRunner.cs +++ b/test/SeqCli.EndToEnd/Support/CliCommandRunner.cs @@ -4,21 +4,15 @@ namespace SeqCli.EndToEnd.Support; -public class CliCommandRunner +public class CliCommandRunner(TestConfiguration configuration) { - readonly TestConfiguration _configuration; static readonly TimeSpan DefaultExecTimeout = TimeSpan.FromSeconds(10); public ITestProcess? LastRunProcess { get; private set; } - public CliCommandRunner(TestConfiguration configuration) - { - _configuration = configuration; - } - public int Exec(string command, string? args = null, bool disconnected = false) { - using var process = _configuration.SpawnCliProcess(command, args, skipServerArg: disconnected); + using var process = configuration.SpawnCliProcess(command, args, skipServerArg: disconnected); LastRunProcess = process; return process.WaitForExit(DefaultExecTimeout); } diff --git a/test/SeqCli.EndToEnd/Support/LicenseCliSetupTestCase.cs b/test/SeqCli.EndToEnd/Support/LicenseSetup.cs similarity index 82% rename from test/SeqCli.EndToEnd/Support/LicenseCliSetupTestCase.cs rename to test/SeqCli.EndToEnd/Support/LicenseSetup.cs index fe6c44a3..67dcfabc 100644 --- a/test/SeqCli.EndToEnd/Support/LicenseCliSetupTestCase.cs +++ b/test/SeqCli.EndToEnd/Support/LicenseSetup.cs @@ -5,18 +5,13 @@ namespace SeqCli.EndToEnd.Support; -public class LicenseSetup +public class LicenseSetup(Args args) { - readonly bool _enabled; + readonly bool _enabled = args.Multiuser(); bool _attempted; string _certificate; - public LicenseSetup(Args args) - { - _enabled = args.Multiuser(); - } - public async Task SetupAsync( SeqConnection connection, ILogger logger) diff --git a/test/SeqCli.EndToEnd/Support/TestConfiguration.cs b/test/SeqCli.EndToEnd/Support/TestConfiguration.cs index fd872954..ee80491a 100644 --- a/test/SeqCli.EndToEnd/Support/TestConfiguration.cs +++ b/test/SeqCli.EndToEnd/Support/TestConfiguration.cs @@ -4,15 +4,8 @@ namespace SeqCli.EndToEnd.Support; -public class TestConfiguration +public class TestConfiguration(Args args) { - readonly Args _args; - - public TestConfiguration(Args args) - { - _args = args; - } - static int ServerListenPort => 9989; #pragma warning disable CA1822 @@ -24,7 +17,7 @@ public TestConfiguration(Args args) public string TestedBinary => Path.Combine(EquivalentBaseDirectory, "seqcli.dll"); - public bool IsMultiuser => _args.Multiuser(); + public bool IsMultiuser => args.Multiuser(); public CaptiveProcess SpawnCliProcess(string command, string additionalArgs = null, Dictionary environment = null, bool skipServerArg = false) { @@ -34,8 +27,7 @@ public CaptiveProcess SpawnCliProcess(string command, string additionalArgs = nu if (!skipServerArg) commandWithArgs += $" --server=\"{ServerListenUrl}\""; - var args = $"{TestedBinary} {commandWithArgs}"; - return new CaptiveProcess("dotnet", args, environment); + return new CaptiveProcess("dotnet", $"{TestedBinary} {commandWithArgs}", environment); } public CaptiveProcess SpawnServerProcess(string storagePath) @@ -43,11 +35,12 @@ public CaptiveProcess SpawnServerProcess(string storagePath) if (storagePath == null) throw new ArgumentNullException(nameof(storagePath)); var commandWithArgs = $"run --listen=\"{ServerListenUrl}\" --storage=\"{storagePath}\""; - if (_args.UseDockerSeq()) + if (args.UseDockerSeq(out var imageTag)) { var containerName = Guid.NewGuid().ToString("n"); - return new CaptiveProcess("docker", $"run --name {containerName} -it --rm -e ACCEPT_EULA=Y -p {ServerListenPort}:80 datalust/seq:latest", stopCommandFullExePath: "docker", stopCommandArgs: $"stop {containerName}"); + return new CaptiveProcess("docker", $"run --name {containerName} -it --rm -e ACCEPT_EULA=Y -p {ServerListenPort}:80 datalust/seq:{imageTag}", stopCommandFullExePath: "docker", stopCommandArgs: $"stop {containerName}"); } + return new CaptiveProcess("seq", commandWithArgs); } } From 72ed0a8c7114991fb5bc3ee35d977cd115e765a9 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 29 Apr 2024 16:38:22 +1000 Subject: [PATCH 2/2] launchSettings.json --- .../Properties/launchSettings.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/SeqCli.EndToEnd/Properties/launchSettings.json diff --git a/test/SeqCli.EndToEnd/Properties/launchSettings.json b/test/SeqCli.EndToEnd/Properties/launchSettings.json new file mode 100644 index 00000000..231d5959 --- /dev/null +++ b/test/SeqCli.EndToEnd/Properties/launchSettings.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "SeqCli.EndToEnd (Seq Executable)": { + "commandName": "Project" + }, + "SeqCli.EndToEnd (datalust/seq:latest)": { + "commandName": "Project", + "commandLineArgs": "--docker-server" + }, + "SeqCli.EndToEnd (datalust/seq:preview)": { + "commandName": "Project", + "commandLineArgs": "--docker-server --pre" + } + } +}