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

Function TestUniqueOpts_validate

insert_opts_test.go:35–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestUniqueOpts_validate(t *testing.T) {
36 t.Parallel()
37
38 require.NoError(t, (&UniqueOpts{}).validate())
39 require.NoError(t, (&UniqueOpts{
40 ByArgs: true,
41 ByPeriod: 1 * time.Second,
42 ByQueue: true,
43 }).validate())
44
45 require.EqualError(t, (&UniqueOpts{ByPeriod: 1 * time.Millisecond}).validate(), "UniqueOpts.ByPeriod should not be less than 1 second")
46 require.EqualError(t, (&UniqueOpts{ByState: []rivertype.JobState{rivertype.JobState("invalid")}}).validate(), `UniqueOpts.ByState contains invalid state "invalid"`)
47
48 requiredStates := []rivertype.JobState{
49 rivertype.JobStateAvailable,
50 rivertype.JobStatePending,
51 rivertype.JobStateRunning,
52 rivertype.JobStateScheduled,
53 }
54
55 for _, state := range requiredStates {
56 // Test with each state individually removed from requiredStates to ensure
57 // it's validated.
58
59 // Create a copy of requiredStates without the current state
60 var testStates []rivertype.JobState
61 for _, s := range requiredStates {
62 if s != state {
63 testStates = append(testStates, s)
64 }
65 }
66
67 // Test validation
68 require.EqualError(t, (&UniqueOpts{ByState: testStates}).validate(), "UniqueOpts.ByState must contain all required states, missing: "+string(state))
69 }
70
71 // test with more than one required state missing:
72 require.EqualError(t, (&UniqueOpts{ByState: []rivertype.JobState{
73 rivertype.JobStateAvailable,
74 rivertype.JobStateScheduled,
75 }}).validate(), "UniqueOpts.ByState must contain all required states, missing: pending, running")
76
77 require.NoError(t, (&UniqueOpts{ByState: rivertype.JobStates()}).validate())
78}

Callers

nothing calls this directly

Calls 3

JobStateTypeAlias · 0.92
JobStatesFunction · 0.92
validateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…