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

Function TestUniqueKey

internal/dbunique/db_unique_test.go:26–521  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24}
25
26func TestUniqueKey(t *testing.T) {
27 t.Parallel()
28
29 // Fixed timestamp for consistency across tests:
30 now := time.Now().UTC()
31 stubSvc := &riversharedtest.TimeStub{}
32 stubSvc.StubNow(now)
33
34 tests := []struct {
35 name string
36 argsFunc func() rivertype.JobArgs
37 modifyInsertParamsFunc func(insertParams *rivertype.JobInsertParams)
38 uniqueOpts UniqueOpts
39 expectedJSON string
40 }{
41 {
42 name: "ByArgsWithMultipleUniqueStructTagsAndDefaultStates",
43 argsFunc: func() rivertype.JobArgs {
44 type EmailJobArgs struct {
45 JobArgsStaticKind
46
47 Recipient string `json:"recipient" river:"unique"`
48 Subject string `json:"subject" river:"unique"`
49 Body string `json:"body"`
50 TemplateID int `json:"template_id"`
51 ScheduledAt string `json:"scheduled_at"`
52 }
53 return EmailJobArgs{
54 JobArgsStaticKind: JobArgsStaticKind{kind: "worker_1"},
55 Recipient: "user@example.com",
56 Subject: "Test Email",
57 Body: "This is a test email.",
58 TemplateID: 101,
59 ScheduledAt: "2024-09-15T10:00:00Z",
60 }
61 },
62 uniqueOpts: UniqueOpts{ByArgs: true},
63 expectedJSON: `&kind=worker_1&args={"recipient":"user@example.com","subject":"Test Email"}`,
64 },
65 {
66 name: "ByArgsWithUniqueFieldsSomeEmpty",
67 argsFunc: func() rivertype.JobArgs {
68 type SMSJobArgs struct {
69 JobArgsStaticKind
70
71 PhoneNumber string `json:"phone_number" river:"unique"`
72 Message string `json:"message,omitempty" river:"unique"`
73 TemplateID int `json:"template_id"`
74 }
75 return SMSJobArgs{
76 JobArgsStaticKind: JobArgsStaticKind{kind: "worker_2"},
77 PhoneNumber: "555-5678",
78 Message: "", // Empty unique field, omitted from key
79 TemplateID: 202,
80 }
81 },
82 uniqueOpts: UniqueOpts{ByArgs: true},
83 expectedJSON: `&kind=worker_2&args={"phone_number":"555-5678"}`,

Callers

nothing calls this directly

Calls 9

StubNowMethod · 0.95
PtrFunction · 0.92
UniqueStatesToBitmaskFunction · 0.92
buildUniqueKeyStringFunction · 0.85
UniqueKeyFunction · 0.85
NowMethod · 0.65
RunMethod · 0.65
KindMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…