summaryrefslogtreecommitdiff
path: root/plugins/jobs/job/job_options_test.go
blob: f4b1dc0ce13c180cfa45f94fbd45ed80c582709e (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package job

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestOptions_CanRetry(t *testing.T) {
	opts := &Options{Attempts: 0}

	assert.False(t, opts.CanRetry(0))
	assert.False(t, opts.CanRetry(1))
}

func TestOptions_CanRetry_SameValue(t *testing.T) {
	opts := &Options{Attempts: 1}

	assert.False(t, opts.CanRetry(0))
	assert.False(t, opts.CanRetry(1))
}

func TestOptions_CanRetry_Value(t *testing.T) {
	opts := &Options{Attempts: 2}

	assert.True(t, opts.CanRetry(0))
	assert.False(t, opts.CanRetry(1))
	assert.False(t, opts.CanRetry(2))
}

func TestOptions_CanRetry_Value3(t *testing.T) {
	opts := &Options{Attempts: 3}

	assert.True(t, opts.CanRetry(0))
	assert.True(t, opts.CanRetry(1))
	assert.False(t, opts.CanRetry(2))
}

func TestOptions_RetryDuration(t *testing.T) {
	opts := &Options{RetryDelay: 0}
	assert.Equal(t, time.Duration(0), opts.RetryDuration())
}

func TestOptions_RetryDuration2(t *testing.T) {
	opts := &Options{RetryDelay: 1}
	assert.Equal(t, time.Second, opts.RetryDuration())
}

func TestOptions_DelayDuration(t *testing.T) {
	opts := &Options{Delay: 0}
	assert.Equal(t, time.Duration(0), opts.DelayDuration())
}

func TestOptions_DelayDuration2(t *testing.T) {
	opts := &Options{Delay: 1}
	assert.Equal(t, time.Second, opts.DelayDuration())
}

func TestOptions_TimeoutDuration(t *testing.T) {
	opts := &Options{Timeout: 0}
	assert.Equal(t, time.Minute*30, opts.TimeoutDuration())
}

func TestOptions_TimeoutDuration2(t *testing.T) {
	opts := &Options{Timeout: 1}
	assert.Equal(t, time.Second, opts.TimeoutDuration())
}

func TestOptions_Merge(t *testing.T) {
	opts := &Options{}

	opts.Merge(&Options{
		Pipeline:   "pipeline",
		Delay:      2,
		Timeout:    1,
		Attempts:   1,
		RetryDelay: 1,
	})

	assert.Equal(t, "pipeline", opts.Pipeline)
	assert.Equal(t, int64(1), opts.Attempts)
	assert.Equal(t, int64(2), opts.Delay)
	assert.Equal(t, int64(1), opts.Timeout)
	assert.Equal(t, int64(1), opts.RetryDelay)
}

func TestOptions_MergeKeepOriginal(t *testing.T) {
	opts := &Options{
		Pipeline:   "default",
		Delay:      10,
		Timeout:    10,
		Attempts:   10,
		RetryDelay: 10,
	}

	opts.Merge(&Options{
		Pipeline:   "pipeline",
		Delay:      2,
		Timeout:    1,
		Attempts:   1,
		RetryDelay: 1,
	})

	assert.Equal(t, "default", opts.Pipeline)
	assert.Equal(t, int64(10), opts.Attempts)
	assert.Equal(t, int64(10), opts.Delay)
	assert.Equal(t, int64(10), opts.Timeout)
	assert.Equal(t, int64(10), opts.RetryDelay)
}