Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 1261969

Browse files
committed
Add ci readme
1 parent 8212be0 commit 1261969

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

ci/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ci
2+
3+
## integration tests
4+
5+
### `tcli`
6+
7+
Package `tcli` provides a framework for writing end-to-end CLI tests.
8+
Each test group can have its own container for executing commands in a consistent
9+
and isolated filesystem.
10+
11+
### prerequisites
12+
13+
Assign the following environment variables to run the integration tests
14+
against an existing Enterprise deployment instance.
15+
16+
```bash
17+
export CODER_URL=...
18+
export CODER_EMAIL=...
19+
export CODER_PASSWORD=...
20+
```
21+
22+
Then, simply run the test command from the project root
23+
24+
```sh
25+
go test -v ./ci/integration
26+
```

ci/integration/integration_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package integration
22

33
import (
44
"context"
5-
"encoding/json"
65
"math/rand"
76
"testing"
87
"time"
98

109
"cdr.dev/coder-cli/ci/tcli"
11-
"cdr.dev/slog"
1210
"cdr.dev/slog/sloggers/slogtest/assert"
1311
)
1412

@@ -76,14 +74,6 @@ func TestCoderCLI(t *testing.T) {
7674
)
7775
}
7876

79-
func stdoutUnmarshalsJSON(target interface{}) tcli.Assertion {
80-
return func(t *testing.T, r *tcli.CommandResult) {
81-
slog.Helper()
82-
err := json.Unmarshal(r.Stdout, target)
83-
assert.Success(t, "json unmarshals", err)
84-
}
85-
}
86-
8777
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
8878

8979
func randString(length int) string {

ci/integration/users_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestUsers(t *testing.T) {
3636
var user entclient.User
3737
c.Run(ctx, `coder users ls --output json | jq -c '.[] | select( .username == "charlie")'`).Assert(t,
3838
tcli.Success(),
39-
stdoutUnmarshalsJSON(&user),
39+
tcli.StdoutJSONUnmarshal(&user),
4040
)
4141
assert.Equal(t, "user email is as expected", "charlie@coder.com", user.Email)
4242
assert.Equal(t, "username is as expected", "Charlie", user.Name)

ci/tcli/tcli.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tcli
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"fmt"
78
"io"
89
"os/exec"
@@ -329,3 +330,21 @@ func DurationGreaterThan(dur time.Duration) Assertion {
329330
}
330331
}
331332
}
333+
334+
// StdoutJSONUnmarshal attempts to unmarshal stdout into the given target
335+
func StdoutJSONUnmarshal(target interface{}) Assertion {
336+
return func(t *testing.T, r *CommandResult) {
337+
slog.Helper()
338+
err := json.Unmarshal(r.Stdout, target)
339+
assert.Success(t, "stdout json unmarshals", err)
340+
}
341+
}
342+
343+
// StderrJSONUnmarshal attempts to unmarshal stderr into the given target
344+
func StderrJSONUnmarshal(target interface{}) Assertion {
345+
return func(t *testing.T, r *CommandResult) {
346+
slog.Helper()
347+
err := json.Unmarshal(r.Stdout, target)
348+
assert.Success(t, "stderr json unmarshals", err)
349+
}
350+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy