FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
river/common_test.go at master · riverqueue/river · GitHub
riverqueue
/
river
Public
Notifications
You must be signed in to change notification settings
Fork
179
Star
5.7k
Code
Issues
38
Pull requests
21
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
river
/
common_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (51 loc) · 1.88 KB
Breadcrumbs
river
/
common_test.go
Copy path
File metadata and controls
63 lines (51 loc) · 1.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
river_test
import
(
"context"
"fmt"
"log/slog"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/riverqueue/river"
"github.com/riverqueue/river/riverdbtest"
"github.com/riverqueue/river/riverdriver/riverpgxv5"
"github.com/riverqueue/river/rivershared/util/slogutil"
"github.com/riverqueue/river/rivershared/util/testutil"
)
//
// This file used as a holding place for test helpers for examples so that the
// helpers aren't included in Godoc and keep each example more succinct.
//
type
NoOpArgs
struct
{}
func
(
NoOpArgs
)
Kind
()
string
{
return
"no_op"
}
type
NoOpWorker
struct
{
river.
WorkerDefaults
[
NoOpArgs
]
}
func
(
w
*
NoOpWorker
)
Work
(
ctx
context.
Context
,
job
*
river.
Job
[
NoOpArgs
])
error
{
fmt
.
Printf
(
"NoOpWorker.Work ran
\n
"
)
return
nil
}
// initTestConfig initializes properties on a given River config with defaults
// suitable for example tests, including an isolated test schema and
// example-friendly logger. It's meant to keep the main example code more terse
// and its use can be removed when copy/pasting from examples.
//
// This helper is intentionally duplicated across example packages so setup
// stays discoverable in each package's docs without introducing an internal
// example-only helper package.
//
// Most workflow examples call this helper to keep setup terse while leaving
// `pgxpool.New` and `river.NewClient` wiring visible in each example.
func
initTestConfig
(
ctx
context.
Context
,
dbPool
*
pgxpool.
Pool
,
config
*
river.
Config
)
*
river.
Config
{
if
config
.
Logger
==
nil
{
// Keep internal client logs off stdout so doctest output stays stable.
config
.
Logger
=
slog
.
New
(
slog
.
NewTextHandler
(
os
.
Stderr
,
&
slog.
HandlerOptions
{
Level
:
slog
.
LevelWarn
,
ReplaceAttr
:
slogutil
.
NoLevelTime
,
}))
}
if
dbPool
!=
nil
{
config
.
Schema
=
riverdbtest
.
TestSchema
(
ctx
,
testutil
.
PanicTB
(),
riverpgxv5
.
New
(
dbPool
),
nil
)
}
config
.
TestOnly
=
true
return
config
}
Back
|
FazBrowse Home
|
New Git URL