-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.go
More file actions
166 lines (129 loc) · 3.97 KB
/
config_test.go
File metadata and controls
166 lines (129 loc) · 3.97 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package gorkflow
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestDefaultExecutionConfig(t *testing.T) {
config := DefaultExecutionConfig
assert.Equal(t, 3, config.MaxRetries)
assert.Equal(t, 1000, config.RetryDelayMs)
assert.Equal(t, BackoffLinear, config.RetryBackoff)
assert.Equal(t, 30, config.TimeoutSeconds)
assert.Equal(t, 1, config.MaxConcurrency)
assert.False(t, config.ContinueOnError)
assert.Nil(t, config.FallbackStepID)
}
func TestWithRetries(t *testing.T) {
step := NewStep("test", "Test", testHandler)
opt := WithRetries(5)
opt.applyStep(step)
assert.Equal(t, 5, step.Config.MaxRetries)
}
func TestWithTimeout(t *testing.T) {
step := NewStep("test", "Test", testHandler)
opt := WithTimeout(60 * time.Second)
opt.applyStep(step)
assert.Equal(t, 60, step.Config.TimeoutSeconds)
}
func TestWithBackoff(t *testing.T) {
step := NewStep("test", "Test", testHandler)
opt := WithBackoff(BackoffExponential)
opt.applyStep(step)
assert.Equal(t, BackoffExponential, step.Config.RetryBackoff)
}
func TestWithRetryDelay(t *testing.T) {
step := NewStep("test", "Test", testHandler)
opt := WithRetryDelay(2 * time.Second)
opt.applyStep(step)
assert.Equal(t, 2000, step.Config.RetryDelayMs)
}
func TestWithContinueOnError(t *testing.T) {
step := NewStep("test", "Test", testHandler)
opt := WithContinueOnError(true)
opt.applyStep(step)
assert.True(t, step.Config.ContinueOnError)
}
func TestStepOptions_Multiple(t *testing.T) {
step := NewStep("test", "Test", testHandler,
WithRetries(5),
WithTimeout(60*time.Second),
WithBackoff(BackoffExponential),
WithRetryDelay(2*time.Second),
WithContinueOnError(true),
)
config := step.GetConfig()
assert.Equal(t, 5, config.MaxRetries)
assert.Equal(t, 60, config.TimeoutSeconds)
assert.Equal(t, BackoffExponential, config.RetryBackoff)
assert.Equal(t, 2000, config.RetryDelayMs)
assert.True(t, config.ContinueOnError)
}
func TestBackoffStrategy_String(t *testing.T) {
assert.Equal(t, "LINEAR", string(BackoffLinear))
assert.Equal(t, "EXPONENTIAL", string(BackoffExponential))
assert.Equal(t, "NONE", string(BackoffNone))
}
func TestWithResourceID(t *testing.T) {
opts := &StartOptions{}
opt := WithResourceID("resource-123")
opt(opts)
assert.Equal(t, "resource-123", opts.ResourceID)
}
func TestWithConcurrencyCheck(t *testing.T) {
opts := &StartOptions{}
opt := WithConcurrencyCheck(true)
opt(opts)
assert.True(t, opts.CheckConcurrency)
}
func TestWithTags(t *testing.T) {
opts := &StartOptions{}
tags := map[string]string{
"env": "production",
"version": "1.0.0",
}
opt := WithTags(tags)
opt(opts)
assert.Equal(t, tags, opts.Tags)
}
func TestStartOptions_Multiple(t *testing.T) {
opts := &StartOptions{}
WithResourceID("resource-123")(opts)
WithConcurrencyCheck(true)(opts)
WithTags(map[string]string{"env": "test"})(opts)
assert.Equal(t, "resource-123", opts.ResourceID)
assert.True(t, opts.CheckConcurrency)
assert.Equal(t, "test", opts.Tags["env"])
}
func TestExecutionConfig_CustomValues(t *testing.T) {
config := ExecutionConfig{
MaxRetries: 10,
RetryDelayMs: 5000,
RetryBackoff: BackoffExponential,
TimeoutSeconds: 120,
MaxConcurrency: 5,
ContinueOnError: true,
}
assert.Equal(t, 10, config.MaxRetries)
assert.Equal(t, 5000, config.RetryDelayMs)
assert.Equal(t, BackoffExponential, config.RetryBackoff)
assert.Equal(t, 120, config.TimeoutSeconds)
assert.Equal(t, 5, config.MaxConcurrency)
assert.True(t, config.ContinueOnError)
}
func TestExecutionConfig_WithFallback(t *testing.T) {
fallbackStep := "fallback-step"
config := ExecutionConfig{
MaxRetries: 3,
TimeoutSeconds: 30,
FallbackStepID: &fallbackStep,
ContinueOnError: true,
}
assert.NotNil(t, config.FallbackStepID)
assert.Equal(t, "fallback-step", *config.FallbackStepID)
}
func TestDefaultEngineConfig(t *testing.T) {
config := DefaultEngineConfig
assert.Equal(t, 10, config.MaxConcurrentWorkflows)
assert.Equal(t, 5*time.Minute, config.DefaultTimeout)
}