Skip to content

Commit ed18461

Browse files
authored
Merge pull request #244 from datalust/dev
2022.1.592 Release
2 parents d62602c + 1945f99 commit ed18461

File tree

13 files changed

+107
-23
lines changed

13 files changed

+107
-23
lines changed

CONTRIBUTING.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Contributing to seqcli
2+
================
3+
4+
Testing
5+
------
6+
7+
`seqcli` has two test projects: `SeqCli.EndToEnd` and `SeqCli.Tests`.
8+
9+
### SeqCli.EndToEnd
10+
11+
`/test/SeqCli.EndToEnd` is a console app that implements integration tests. It uses a custom testing framework and xunit for assertions.
12+
13+
Each test within the EndToEnd project (an implementation of the `ICliTestCase` interface) spans one child process for the Seq server and one child process for the seqcli command.
14+
15+
The Seq server can be run via the `seq` executable (windows only) or as a `datalust/seq:latest` docker container. Which to use is controlled via the `--docker-server` argument.
16+
17+
Some tests require a Seq license. These tests are run if a valid license is supplied via stdin and the `--license-certificate-stdin` argument is supplied.
18+
19+
#### Adding Tests
20+
21+
The typical pattern is to execute a seqcli command, then make an assertion on the output of the command. E.g.
22+
23+
```c#
24+
var exit = runner.Exec("apikey list", "-t Test --json --no-color");
25+
Assert.Equal(0, exit);
26+
27+
var output = runner.LastRunProcess!.Output;
28+
Assert.Contains("\"AssignedPermissions\": [\"Ingest\"]", output);
29+
```
30+
31+
#### Running Tests
32+
33+
```shell
34+
/SeqCli.EndToEnd$ dotnet run -- --docker-server
35+
```
36+
37+
The `--docker-server` is optional if you have a `seq` executable in your path.
38+
39+
To run the multi user tests as well, save a valid license into a file and:
40+
41+
```shell
42+
/SeqCli.EndToEnd$ cat license.txt | dotnet run -- --docker-server --license-certificate-stdin
43+
```
44+
45+
To run a specific set of tests pass regular expressions matching the tests to run:
46+
47+
```shell
48+
/SeqCli.EndToEnd$ dotnet run -- --docker-server *TestCase.cs Command*
49+
```
50+
51+
### SeqCli.Tests
52+
53+
`/test/SeqCli.Tests` is a regular xunit testing project. To run:
54+
55+
```shell
56+
/SeqCli.Tests$ dotnet test
57+
```

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ $token = (
5050
)
5151
```
5252

53+
## Contributing
54+
55+
See `CONTRIBUTING.md`.
56+
5357
## Commands
5458

5559
Usage:

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.201"
3+
"version": "6.0.301"
44
}
55
}

seqcli.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{2EA56595-519
1717
Build.Docker.ps1 = Build.Docker.ps1
1818
docker-publish.ps1 = docker-publish.ps1
1919
Setup.ps1 = Setup.ps1
20+
CONTRIBUTING.md = CONTRIBUTING.md
2021
EndProjectSection
2122
EndProject
2223
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3587B633-0C03-4235-8903-6226900328F1}"

src/SeqCli/Cli/Commands/ApiKey/CreateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
namespace SeqCli.Cli.Commands.ApiKey
3030
{
31-
[Command("apikey", "create", "Create an API key for ingestion",
31+
[Command("apikey", "create", "Create an API key for automation or ingestion",
3232
Example = "seqcli apikey create -t 'Test API Key' -p Environment=Test")]
3333
class CreateCommand : Command
3434
{

src/SeqCli/Cli/Commands/PrintCommand.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ class PrintCommand : Command
3535
readonly InvalidDataHandlingFeature _invalidDataHandlingFeature;
3636

3737
string _filter, _template = OutputFormatFeature.DefaultOutputTemplate;
38-
bool _noColor;
38+
bool _noColor, _forceColor;
3939

4040
public PrintCommand(SeqCliOutputConfig outputConfig)
4141
{
4242
if (outputConfig == null) throw new ArgumentNullException(nameof(outputConfig));
4343
_noColor = outputConfig.DisableColor;
44+
_forceColor = outputConfig.ForceColor;
4445

4546
_fileInputFeature = Enable(new FileInputFeature("CLEF file to read", supportsWildcard: true));
4647

@@ -55,17 +56,30 @@ public PrintCommand(SeqCliOutputConfig outputConfig)
5556
_invalidDataHandlingFeature = Enable<InvalidDataHandlingFeature>();
5657

5758
Options.Add("no-color", "Don't colorize text output", v => _noColor = true);
59+
60+
Options.Add("force-color",
61+
"Force redirected output to have ANSI color (unless `--no-color` is also specified)",
62+
v => _forceColor = true);
5863
}
5964

6065
protected override async Task<int> Run()
6166
{
67+
var applyThemeToRedirectedOutput
68+
= _noColor == false && _forceColor == true;
69+
70+
var theme
71+
= _noColor ? ConsoleTheme.None
72+
: applyThemeToRedirectedOutput ? OutputFormatFeature.DefaultAnsiTheme
73+
: OutputFormatFeature.DefaultTheme;
74+
6275
var outputConfiguration = new LoggerConfiguration()
6376
.MinimumLevel.Is(LevelAlias.Minimum)
6477
.Enrich.With<RedundantEventTypeRemovalEnricher>()
6578
.Enrich.With<SurrogateLevelRemovalEnricher>()
6679
.WriteTo.Console(
6780
outputTemplate: _template,
68-
theme: _noColor ? ConsoleTheme.None : OutputFormatFeature.DefaultTheme);
81+
theme: theme,
82+
applyThemeToRedirectedOutput: applyThemeToRedirectedOutput);
6983

7084
if (_filter != null)
7185
outputConfiguration.Filter.ByIncludingOnly(_filter);

src/SeqCli/Cli/Commands/Sample/SetupCommand.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ protected override async Task<int> Run()
5959
}
6060

6161
var templateArgs = new Dictionary<string, JsonTemplate>();
62-
var users = await connection.Users.ListAsync();
63-
if (users.Count == 1)
64-
templateArgs["ownerId"] = new JsonTemplateString(users.Single().Id);
65-
else
66-
templateArgs["ownerId"] = new JsonTemplateNull();
62+
templateArgs["ownerId"] = new JsonTemplateNull();
6763

6864
var templatesPath = Content.GetPath(Path.Combine("Sample", "Templates"));
6965
var templateFiles = Directory.GetFiles(templatesPath);

src/SeqCli/Cli/Features/OutputFormatFeature.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,25 @@ class OutputFormatFeature : CommandFeature
3434
public const string DefaultOutputTemplate =
3535
"[{Timestamp:o} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}";
3636

37-
public static readonly ConsoleTheme DefaultTheme = SystemConsoleTheme.Literate;
37+
public static readonly ConsoleTheme DefaultTheme = SystemConsoleTheme.Literate;
38+
public static readonly ConsoleTheme DefaultAnsiTheme = AnsiConsoleTheme.Code;
3839

39-
bool _json, _noColor;
40+
bool _json, _noColor, _forceColor;
4041

4142
public OutputFormatFeature(SeqCliOutputConfig outputConfig)
4243
{
4344
_noColor = outputConfig.DisableColor;
45+
_forceColor = outputConfig.ForceColor;
4446
}
4547

4648
public bool Json => _json;
4749

48-
ConsoleTheme Theme => _noColor ? ConsoleTheme.None : DefaultTheme;
50+
bool ApplyThemeToRedirectedOutput => _noColor == false && _forceColor == true;
51+
52+
ConsoleTheme Theme
53+
=> _noColor ? ConsoleTheme.None
54+
: ApplyThemeToRedirectedOutput ? DefaultAnsiTheme
55+
: DefaultTheme;
4956

5057
public override void Enable(OptionSet options)
5158
{
@@ -55,6 +62,10 @@ public override void Enable(OptionSet options)
5562
v => _json = true);
5663

5764
options.Add("no-color", "Don't colorize text output", v => _noColor = true);
65+
66+
options.Add("force-color",
67+
"Force redirected output to have ANSI color (unless `--no-color` is also specified)",
68+
v => _forceColor = true);
5869
}
5970

6071
public Logger CreateOutputLogger()
@@ -72,7 +83,8 @@ public Logger CreateOutputLogger()
7283
outputConfiguration.Enrich.With<SurrogateLevelRemovalEnricher>();
7384
outputConfiguration.WriteTo.Console(
7485
outputTemplate: DefaultOutputTemplate,
75-
theme: Theme);
86+
theme: Theme,
87+
applyThemeToRedirectedOutput: ApplyThemeToRedirectedOutput);
7688
}
7789

7890
return outputConfiguration.CreateLogger();
@@ -115,7 +127,8 @@ public void WriteEntity(Entity entity)
115127
.Enrich.With<StripStructureTypeEnricher>()
116128
.WriteTo.Console(
117129
outputTemplate: "{@Message:j}{NewLine}",
118-
theme: Theme)
130+
theme: Theme,
131+
applyThemeToRedirectedOutput: ApplyThemeToRedirectedOutput)
119132
.CreateLogger();
120133
writer.Information("{@Entity}", jo);
121134
}

src/SeqCli/Config/SeqCliOutputConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ namespace SeqCli.Config
1717
class SeqCliOutputConfig
1818
{
1919
public bool DisableColor { get; set; }
20+
public bool ForceColor { get; set; }
2021
}
2122
}

src/SeqCli/SeqCli.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
<ItemGroup>
2424
<PackageReference Include="Destructurama.JsonNet" Version="2.0.0" />
2525
<PackageReference Include="newtonsoft.json" Version="13.0.1" />
26-
<PackageReference Include="Serilog" Version="2.10.0" />
26+
<PackageReference Include="Serilog" Version="2.11.0" />
2727
<PackageReference Include="serilog.filters.expressions" Version="2.1.0" />
2828
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
2929
<PackageReference Include="Serilog.Formatting.Compact.Reader" Version="1.0.5" />
3030
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
31-
<PackageReference Include="Autofac" Version="6.3.0" />
31+
<PackageReference Include="Autofac" Version="6.4.0" />
3232
<PackageReference Include="Superpower" Version="3.0.0" />
3333
<PackageReference Include="System.Reactive" Version="5.0.0" />
3434
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />

0 commit comments

Comments
 (0)