-
Notifications
You must be signed in to change notification settings - Fork 15
/
common_test.go
64 lines (48 loc) · 1.36 KB
/
common_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package riverui
import (
"context"
"encoding/json"
"log/slog"
"testing"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/require"
"github.com/riverqueue/river"
"github.com/riverqueue/river/riverdriver"
"github.com/riverqueue/river/riverdriver/riverpgxv5"
)
type noOpArgs struct {
Name string `json:"name"`
}
func (noOpArgs) Kind() string { return "noOp" }
type noOpWorker struct {
river.WorkerDefaults[noOpArgs]
}
func (w *noOpWorker) Work(_ context.Context, _ *river.Job[noOpArgs]) error { return nil }
func insertOnlyClient(t *testing.T, logger *slog.Logger) (*river.Client[pgx.Tx], riverdriver.Driver[pgx.Tx]) {
t.Helper()
workers := river.NewWorkers()
river.AddWorker(workers, &noOpWorker{})
driver := riverpgxv5.New(nil)
client, err := river.NewClient(driver, &river.Config{
Logger: logger,
Workers: workers,
})
require.NoError(t, err)
return client, driver
}
func mustMarshalJSON(t *testing.T, v any) []byte {
t.Helper()
data, err := json.Marshal(v)
require.NoError(t, err)
return data
}
// Requires that err is an equivalent API error to expectedErr.
//
// TError is a pointer to an API error type like *apierror.NotFound.
func requireAPIError[TError error](t *testing.T, expectedErr TError, err error) {
t.Helper()
require.Error(t, err)
var apiErr TError
require.ErrorAs(t, err, &apiErr)
require.Equal(t, expectedErr, apiErr)
}