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

Migrate to cobra #86

Merged
merged 10 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add ci readme
  • Loading branch information
cmoog committed Aug 10, 2020
commit 12619695323959a4b70e5e688a9fc7d34a5d5377
26 changes: 26 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ci
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to link to this from the README.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most readers of the README will be customers, not developers. Doesn't really make sense to bring attention to it in my view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have to bring attention to it. Just put a link at the bottom. Customers/potential customers who care to look closely will be happy we document and care about these things.


## integration tests

### `tcli`

Package `tcli` provides a framework for writing end-to-end CLI tests.
Each test group can have its own container for executing commands in a consistent
and isolated filesystem.

### prerequisites

Assign the following environment variables to run the integration tests
against an existing Enterprise deployment instance.

```bash
export CODER_URL=...
export CODER_EMAIL=...
export CODER_PASSWORD=...
```

Then, simply run the test command from the project root

```sh
go test -v ./ci/integration
```
10 changes: 0 additions & 10 deletions ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package integration

import (
"context"
"encoding/json"
"math/rand"
"testing"
"time"

"cdr.dev/coder-cli/ci/tcli"
"cdr.dev/slog"
"cdr.dev/slog/sloggers/slogtest/assert"
)

Expand Down Expand Up @@ -76,14 +74,6 @@ func TestCoderCLI(t *testing.T) {
)
}

func stdoutUnmarshalsJSON(target interface{}) tcli.Assertion {
return func(t *testing.T, r *tcli.CommandResult) {
slog.Helper()
err := json.Unmarshal(r.Stdout, target)
assert.Success(t, "json unmarshals", err)
}
}

var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))

func randString(length int) string {
Expand Down
2 changes: 1 addition & 1 deletion ci/integration/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestUsers(t *testing.T) {
var user entclient.User
c.Run(ctx, `coder users ls --output json | jq -c '.[] | select( .username == "charlie")'`).Assert(t,
tcli.Success(),
stdoutUnmarshalsJSON(&user),
tcli.StdoutJSONUnmarshal(&user),
)
assert.Equal(t, "user email is as expected", "charlie@coder.com", user.Email)
assert.Equal(t, "username is as expected", "Charlie", user.Name)
Expand Down
19 changes: 19 additions & 0 deletions ci/tcli/tcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tcli
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os/exec"
Expand Down Expand Up @@ -329,3 +330,21 @@ func DurationGreaterThan(dur time.Duration) Assertion {
}
}
}

// StdoutJSONUnmarshal attempts to unmarshal stdout into the given target
func StdoutJSONUnmarshal(target interface{}) Assertion {
return func(t *testing.T, r *CommandResult) {
slog.Helper()
err := json.Unmarshal(r.Stdout, target)
assert.Success(t, "stdout json unmarshals", err)
}
}

// StderrJSONUnmarshal attempts to unmarshal stderr into the given target
func StderrJSONUnmarshal(target interface{}) Assertion {
return func(t *testing.T, r *CommandResult) {
slog.Helper()
err := json.Unmarshal(r.Stdout, target)
assert.Success(t, "stderr json unmarshals", err)
}
}