Skip to content

Commit

Permalink
readme: add notes on util package
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Sep 4, 2024
1 parent a592af6 commit 2d5b3c3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ There are five key packages,
- `test` - assertions causing test failure and allow the test case to continue
- `wait` - utilities for waiting on conditionals in tests
- `skip` - utilities for skipping test cases in some situations
- `util` - utilities for writing concise tests, e.g. managing temp files
- `portal` - utilities for allocating free ports for network listeners in tests

### Changes
Expand Down Expand Up @@ -193,6 +194,21 @@ skip.CommandUnavailable(t, "java")
skip.EnvironmentVariableSet(t, "CI")
```

### Util

How often have you written a helper method for writing a temporary file in unit
tests? With the `util` package, that boilerplate is resolved once and for all.

```go
path := util.TempFile(t,
util.Mode(0o644),
util.String("some content!"),
)
```

The file referenced by `path` will be cleaned up automatically at the end of
the test run, similar to `t.TempDir()`.

### Wait

Sometimes a test needs to wait on a condition for a non-deterministic amount of time.
Expand Down

0 comments on commit 2d5b3c3

Please sign in to comment.