forked from riverqueue/river
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_test.go
35 lines (27 loc) · 1.08 KB
/
job_test.go
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
package river
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"weavelab.xyz/river/rivertype"
)
func TestJobUniqueOpts_isEmpty(t *testing.T) {
t.Parallel()
require.True(t, (&UniqueOpts{}).isEmpty())
require.False(t, (&UniqueOpts{ByArgs: true}).isEmpty())
require.False(t, (&UniqueOpts{ByPeriod: 1 * time.Nanosecond}).isEmpty())
require.False(t, (&UniqueOpts{ByQueue: true}).isEmpty())
require.False(t, (&UniqueOpts{ByState: []rivertype.JobState{JobStateAvailable}}).isEmpty())
}
func TestJobUniqueOpts_validate(t *testing.T) {
t.Parallel()
require.NoError(t, (&UniqueOpts{}).validate())
require.NoError(t, (&UniqueOpts{
ByArgs: true,
ByPeriod: 1 * time.Second,
ByQueue: true,
ByState: []rivertype.JobState{JobStateAvailable},
}).validate())
require.EqualError(t, (&UniqueOpts{ByPeriod: 1 * time.Millisecond}).validate(), "JobUniqueOpts.ByPeriod should not be less than 1 second")
require.EqualError(t, (&UniqueOpts{ByState: []rivertype.JobState{rivertype.JobState("invalid")}}).validate(), `JobUniqueOpts.ByState contains invalid state "invalid"`)
}