MCPcopy Index your code
hub / github.com/riverqueue/river / TestClientFromContext

Function TestClientFromContext

context_test.go:11–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestClientFromContext(t *testing.T) {
12 t.Parallel()
13
14 ctx := context.Background()
15 client := &Client[pgx.Tx]{}
16 ctx = withClient(ctx, client)
17
18 require.Equal(t, client, ClientFromContext[pgx.Tx](ctx))
19
20 result, err := ClientFromContextSafely[pgx.Tx](ctx)
21 require.NoError(t, err)
22 require.Equal(t, client, result)
23
24 require.PanicsWithError(t, errClientNotInContext.Error(), func() {
25 ClientFromContext[pgx.Tx](context.Background())
26 })
27
28 result, err = ClientFromContextSafely[pgx.Tx](context.Background())
29 require.ErrorIs(t, err, errClientNotInContext)
30 require.Nil(t, result)
31}

Callers

nothing calls this directly

Calls 2

withClientFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…