-
Notifications
You must be signed in to change notification settings - Fork 881
Expand file tree
/
Copy pathsettings_apply_test.go
More file actions
80 lines (75 loc) · 2.49 KB
/
Copy pathsettings_apply_test.go
File metadata and controls
80 lines (75 loc) · 2.49 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
package service
import (
"testing"
"github.com/flyteorg/flyte/v2/gen/go/flyteidl2/settings"
"github.com/flyteorg/flyte/v2/gen/go/flyteidl2/task"
"github.com/stretchr/testify/assert"
)
func runSettings(queue *settings.StringSetting, concurrency *settings.Int64Setting) *settings.Settings {
return &settings.Settings{
Run: &settings.RunSettings{DefaultQueue: queue, MaxActionConcurrency: concurrency},
}
}
func TestApplyRunSettings(t *testing.T) {
tests := []struct {
name string
spec *task.RunSpec
resolved *settings.Settings
wantQueue string
wantConcurrency uint32
}{
{
name: "empty queue takes the settings value",
spec: &task.RunSpec{},
resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil),
wantQueue: "fast-queue",
},
{
name: "an explicit queue wins over settings",
spec: &task.RunSpec{Queue: "user-queue"},
resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil),
wantQueue: "user-queue",
},
{
name: "a queue in INHERIT contributes nothing",
spec: &task.RunSpec{},
resolved: runSettings(&settings.StringSetting{State: stateInherit, StringValue: "fast-queue"}, nil),
wantQueue: "",
},
{
name: "zero concurrency takes the settings value",
spec: &task.RunSpec{},
resolved: runSettings(nil, &settings.Int64Setting{State: stateValue, IntValue: 5}),
wantConcurrency: 5,
},
{
name: "an explicit concurrency wins over settings",
spec: &task.RunSpec{MaxActionConcurrency: 3},
resolved: runSettings(nil, &settings.Int64Setting{State: stateValue, IntValue: 5}),
wantConcurrency: 3,
},
{
name: "concurrency in UNSET contributes nothing",
spec: &task.RunSpec{},
resolved: runSettings(nil, &settings.Int64Setting{State: stateUnset, IntValue: 5}),
wantConcurrency: 0,
},
{
name: "no settings at all",
spec: &task.RunSpec{},
resolved: &settings.Settings{},
},
{
name: "nil spec does not panic",
spec: nil,
resolved: runSettings(&settings.StringSetting{State: stateValue, StringValue: "fast-queue"}, nil),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
applyRunSettings(tt.spec, tt.resolved)
assert.Equal(t, tt.wantQueue, tt.spec.GetQueue())
assert.Equal(t, tt.wantConcurrency, tt.spec.GetMaxActionConcurrency())
})
}
}