2023-02-02 17:15:17 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-05-06 14:54:10 -07:00
|
|
|
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("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)
|
|
|
|
|
})
|
2022-05-18 17:03:24 -07:00
|
|
|
t.Run("WithControllerId", func(t *testing.T) {
|
2021-05-06 14:54:10 -07:00
|
|
|
assert := assert.New(t)
|
2022-05-18 17:03:24 -07:00
|
|
|
opts := getOpts(WithControllerId("controller_id"))
|
2021-05-06 14:54:10 -07:00
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
assert.NotEqual(opts, testOpts)
|
2022-05-18 17:03:24 -07:00
|
|
|
testOpts.withControllerId = "controller_id"
|
2021-05-06 14:54:10 -07:00
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
}
|