Skip to content

Commit 3a25d0b

Browse files
authored
Merge pull request #242 from liammclennan/sample-setup-system-apikeys
Don't set owner on `seqcli sample setup` template items.
2 parents fae79fb + 3ea8b71 commit 3a25d0b

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
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:

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/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);

test/SeqCli.EndToEnd/Sample/SampleSetupTestCase.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ public async Task ExecuteAsync(SeqConnection connection, ILogger logger, CliComm
1313
{
1414
var exit = runner.Exec("sample setup", "--confirm");
1515
Assert.Equal(0, exit);
16-
17-
var currentUserId = (await connection.Users.FindCurrentAsync()).Id;
18-
19-
// Depends on the most other entities, so is a pretty good proxy for success.
20-
var sampleWorkspace = (await connection.Workspaces.ListAsync(ownerId: currentUserId))
16+
17+
var sampleWorkspace = (await connection.Workspaces.ListAsync(shared: true))
2118
.SingleOrDefault(w => w.Title == "Sample");
2219

2320
Assert.NotNull(sampleWorkspace);

test/SeqCli.EndToEnd/Support/TestConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public CaptiveProcess SpawnServerProcess(string storagePath)
4343
var commandWithArgs = $"run --listen=\"{ServerListenUrl}\" --storage=\"{storagePath}\"";
4444
if (_args.UseDockerSeq())
4545
{
46-
return new CaptiveProcess("docker", $"run --name seq -it --rm -e ACCEPT_EULA=Y -p {ServerListenPort}:80 datalust/seq:latest", stopCommandFullExePath: "docker", stopCommandArgs: "stop seq");
46+
var containerName = Guid.NewGuid().ToString("n");
47+
return new CaptiveProcess("docker", $"run --name {containerName} -it --rm -e ACCEPT_EULA=Y -p {ServerListenPort}:80 datalust/seq:latest", stopCommandFullExePath: "docker", stopCommandArgs: $"stop {containerName}");
4748
}
4849
return new CaptiveProcess("seq", commandWithArgs);
4950
}

0 commit comments

Comments
 (0)