forked from argoproj/argo-workflows
/
operator_workflow_template_ref_test.go
163 lines (149 loc) · 4.23 KB
/
operator_workflow_template_ref_test.go
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
package controller
import (
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/intstr"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/util"
)
func TestWorkflowTemplateRef(t *testing.T) {
cancel, controller := newController(unmarshalWF(wfWithTmplRef), unmarshalWFTmpl(wfTmpl))
defer cancel()
woc := newWorkflowOperationCtx(unmarshalWF(wfWithTmplRef), controller)
woc.operate()
assert.Equal(t, unmarshalWFTmpl(wfTmpl).Spec.WorkflowSpec.Templates, woc.wfSpec.Templates)
assert.Equal(t, woc.wf.Spec.Entrypoint, woc.wfSpec.Entrypoint)
// verify we copy these values
assert.Len(t, woc.volumes, 1, "volumes from workflow template")
// and these
assert.Equal(t, "my-sa", woc.globalParams["workflow.serviceAccountName"])
assert.Equal(t, "77", woc.globalParams["workflow.priority"])
}
func TestWorkflowTemplateRefWithArgs(t *testing.T) {
wf := unmarshalWF(wfWithTmplRef)
wftmpl := unmarshalWFTmpl(wfTmpl)
t.Run("CheckArgumentPassing", func(t *testing.T) {
value := intstr.Parse("test")
args := []wfv1.Parameter{
{
Name: "param1",
Value: &value,
},
}
wf.Spec.Arguments.Parameters = util.MergeParameters(wf.Spec.Arguments.Parameters, args)
cancel, controller := newController(wf, wftmpl)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
assert.Equal(t, "test", woc.globalParams["workflow.parameters.param1"])
})
}
func TestWorkflowTemplateRefWithWorkflowTemplateArgs(t *testing.T) {
wf := unmarshalWF(wfWithTmplRef)
wftmpl := unmarshalWFTmpl(wfTmpl)
t.Run("CheckArgumentFromWFT", func(t *testing.T) {
value := intstr.Parse("test")
args := []wfv1.Parameter{
{
Name: "param1",
Value: &value,
},
}
wftmpl.Spec.Arguments.Parameters = util.MergeParameters(wf.Spec.Arguments.Parameters, args)
cancel, controller := newController(wf, wftmpl)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
assert.Equal(t, "test", woc.globalParams["workflow.parameters.param1"])
})
}
const wfWithStatus = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: workflow-template-whalesay-template-
namespace: argo
spec:
arguments:
parameters:
- name: param1
value: test
entrypoint: whalesay-template
workflowTemplateRef:
name: workflow-template-whalesay-template
status:
startedAt: "2020-05-01T01:04:41Z"
storedTemplates:
namespaced/workflow-template-whalesay-template/whalesay-template:
arguments: {}
container:
args:
- '{{inputs.parameters.message}}'
command:
- cowsay
image: docker/whalesay
name: ""
resources: {}
inputs:
parameters:
- name: message
metadata: {}
name: whalesay-template
outputs: {}
storedWorkflowTemplateSpec:
arguments:
parameters:
- name: param2
value: hello
templates:
- arguments: {}
container:
args:
- '{{inputs.parameters.message}}'
command:
- cowsay
image: docker/whalesay
name: ""
resources: {}
inputs:
parameters:
- name: message
metadata: {}
name: whalesay-template
outputs: {}
`
func TestWorkflowTemplateRefGetFromStored(t *testing.T) {
wf := unmarshalWF(wfWithStatus)
t.Run("ProcessWFWithStoredWFT", func(t *testing.T) {
cancel, controller := newController(wf)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
_, execArgs, err := woc.loadExecutionSpec()
assert.NoError(t, err)
assert.Equal(t, "test", execArgs.Parameters[0].Value.String())
assert.Equal(t, "hello", execArgs.Parameters[1].Value.String())
})
}
const invalidWF = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: ui-workflow-error
namespace: argo
spec:
entrypoint: main
workflowTemplateRef:
name: not-exists
`
func TestWorkflowTemplateRefInvalidWF(t *testing.T) {
wf := unmarshalWF(invalidWF)
t.Run("ProcessWFWithStoredWFT", func(t *testing.T) {
cancel, controller := newController(wf)
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
_, _, err := woc.loadExecutionSpec()
assert.Error(t, err)
woc.operate()
assert.Equal(t, wfv1.NodeError, woc.wf.Status.Phase)
})
}