-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathmetadata_test.go
More file actions
41 lines (29 loc) · 1.07 KB
/
Copy pathmetadata_test.go
File metadata and controls
41 lines (29 loc) · 1.07 KB
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
package river
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/riverqueue/river/internal/jobexecutor"
)
func TestMetadataSet(t *testing.T) {
t.Parallel()
t.Run("RejectsReservedPrefix", func(t *testing.T) {
t.Parallel()
ctx := context.WithValue(context.Background(), jobexecutor.ContextKeyMetadataUpdates, map[string]any{})
err := MetadataSet(ctx, "river:reserved", "value")
require.EqualError(t, err, "MetadataSet cannot be used with keys prefixed with `river:`")
})
t.Run("RequiresWorkContext", func(t *testing.T) {
t.Parallel()
err := MetadataSet(context.Background(), "key", "value")
require.EqualError(t, err, "MetadataSet must be called within a worker, worker middleware, or work hook")
})
t.Run("SetsValueOnWorkContext", func(t *testing.T) {
t.Parallel()
metadataUpdates := map[string]any{}
ctx := context.WithValue(context.Background(), jobexecutor.ContextKeyMetadataUpdates, metadataUpdates)
err := MetadataSet(ctx, "key", "value")
require.NoError(t, err)
require.Equal(t, "value", metadataUpdates["key"])
})
}