Files
threshold/internal/scheduler/job/options_test.go
T
Louis Ruch feb5d7385d Louis job scheduler (#1197)
* Adds job repo
* Adds scheduler
* Adds plugin table which is a place holder for future expansion of the scheduler. Currently all jobs that are created are linked to the pi_system plugin which are jobs that are held in a local registeredJobs map populated at controller startup.
2021-05-06 14:54:10 -07:00

61 lines
1.6 KiB
Go

package job
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// Test_GetOpts provides unit tests for GetOpts and all the options
func Test_GetOpts(t *testing.T) {
t.Parallel()
t.Run("WithNextRunIn", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithNextRunIn(time.Hour))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withNextRunIn = time.Hour
assert.Equal(opts, testOpts)
})
t.Run("WithRunJobsLimit", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithRunJobsLimit(10))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withRunJobsLimit = 10
assert.Equal(opts, testOpts)
})
t.Run("WithZeroRunJobsLimit", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithRunJobsLimit(0))
testOpts := getDefaultOptions()
assert.Equal(opts, testOpts)
assert.Equal(uint(defaultRunJobsLimit), opts.withRunJobsLimit)
})
t.Run("WithLimit", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithLimit(100))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withLimit = 100
assert.Equal(opts, testOpts)
})
t.Run("WithName", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithName("name"))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withName = "name"
assert.Equal(opts, testOpts)
})
t.Run("WithServerId", func(t *testing.T) {
assert := assert.New(t)
opts := getOpts(WithServerId("server_id"))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.withServerId = "server_id"
assert.Equal(opts, testOpts)
})
}