Skip to content

Commit

Permalink
v5.3.0 changelog and docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed Sep 22, 2024
1 parent 9f2c0b8 commit 61e4a49
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.23'
cache: false
- name: Run spellcheck
run: |
Expand Down
160 changes: 80 additions & 80 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"medium-zoom": "^1.1.0",
"vite-svg-loader": "^5.1.0",
"vitepress": "^1.3.4",
"vue": "^3.4.38"
"vue": "^3.5.8"
},
"author": "Jérémy LAMBERT (System-Glitch)",
"license": "MIT",
Expand Down
18 changes: 17 additions & 1 deletion src/advanced/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Goyave is test framework agnostic. You can use any testing library you want and
- Create test responses
- Test an endpoint without starting the server and listen on a network port
- Test middleware
- Redirect logs to the testing logger
- Discard logs to make them silent by default
- Load the config from the project's root directory easily
- Run the tests inside a transaction that can be easily rolled back

Expand Down Expand Up @@ -114,6 +114,22 @@ func TestMockDB(t *testing.T) {
Test servers automatically close the database in a test cleanup hook. If you are using `go-sqlmock`, this will generate an error for unexpected `Close` unless you add `mock.ExpectClose()` at the very end of your test.
:::

### Logs

The default logger for test servers is `slog.DiscardLogger()`, which outputs to `io.Discard`, making logs silent.

You may want to print logs coming from your tests for functional reasons or for debugging. `testutil.LogWriter` is an implementation of `io.Writer` that redirects logs to `testing.T.Log()` for better readability.

```go
func TestSomething(t *testing.T) {
opts := goyave.Options{
Logger: slog.New(slog.NewHandler(true, &testutil.LogWriter{t: t})),
}
server := testutil.NewTestServerWithOptions(t, opts)
//...
}
```

## HTTP Tests

You may want to write tests that simulate how a client would interact with your API through HTTP calls. In order to do so, use the test server's `TestRequest(*http.Request)` method. It will execute the request all the way from the router's `ServeHTTP()` implementation. Therefore, the request's lifecycle will be executed from start to finish.
Expand Down
1 change: 1 addition & 0 deletions src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ You can also see the changelog on [Github](https://github.com/go-goyave/goyave/r
You can be notified of new releases by enabling notifications on Github or by joining our [Discord](https://discord.gg/mfemDMc).
:::

- [v5.3.0](./changelog/v5.3.0.md)
- [v5.2.1](./changelog/v5.2.1.md)
- [v5.2.0](./changelog/v5.2.0.md)
- [v5.1.1](./changelog/v5.1.1.md)
Expand Down
4 changes: 3 additions & 1 deletion src/changelog/v5.2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ description: "The detailed release notes for v5.2.1"
prev:
text: 'v5.2.0'
link: '/changelog/v5.2.0'
next: false
next:
text: 'v5.3.0'
link: '/changelog/v5.3.0'
---

# v5.2.1 release notes
Expand Down
24 changes: 24 additions & 0 deletions src/changelog/v5.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: "v5.3.0 release notes"
description: "The detailed release notes for v5.3.0"
prev:
text: 'v5.2.1'
link: '/changelog/v5.2.1'
next: false
---

# v5.3.0 release notes

- Added `slog.DiscardLogger()`, which redirects logs to `io.Discard`.
- `testutil.TestServer` now uses the discard logger by default instead of `testutil.LogWriter`.

This change was made so logs written during tests should usually be silent. To make it more convenient, this is now the default behavior. Sometimes it is still handy to see logs while writing or debugging a test. For this use-case, you can use `testutil.LogWriter`:
```go
func TestSomething(t *testing.T) {
opts := goyave.Options{
Logger: slog.New(slog.NewHandler(true, &testutil.LogWriter{t: t})),
}
server := testutil.NewTestServerWithOptions(t, opts)
//...
}
```
1 change: 1 addition & 0 deletions src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ A big "Thank you" to the Goyave contributors:
- [Muhammad Meganata Adam](https://github.com/bangadam) (`DoesntEndWithValidator`, `KeysInValidator`)
- [BowlOfSoup](https://github.com/BowlOfSoup) (`Required` flag in configuration entries, `ParseErrorStatusHandler`)
- [AidanKenney](https://github.com/AidanKenney) (Clickhouse support, compression encoders)
- [SallesCosta](https://github.com/SallesCosta) (Slog discard logger)

## Goyave in production

Expand Down

0 comments on commit 61e4a49

Please sign in to comment.