Skip to content

Commit 39b1e90

Browse files
Copilotintel352
andauthored
wftest YAML runner: add schedule and event trigger types (#369)
* Initial plan * feat(wftest): add schedule and event trigger types to YAML runner Co-authored-by: intel352 <77607+intel352@users.noreply.github.com> Agent-Logs-Url: https://github.com/GoCodeAlone/workflow/sessions/9b9c11ba-fdb7-42ff-92d6-aee0baa7bc65 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: intel352 <77607+intel352@users.noreply.github.com> Co-authored-by: Jonathan Langevin <codingsloth@pm.me>
1 parent 8878765 commit 39b1e90

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

wftest/yaml_runner.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ func fireTrigger(t *testing.T, h *Harness, tc *TestCase) *Result {
200200
}
201201
return h.POST(tc.Trigger.Path, body, reqOpts...)
202202

203+
case "schedule":
204+
name := tc.Trigger.Name
205+
if name == "" {
206+
t.Fatal("RunYAMLTests: trigger.name is required for schedule triggers")
207+
}
208+
return h.FireSchedule(name, tc.Trigger.Data)
209+
210+
case "event", "eventbus":
211+
topic := tc.Trigger.Name
212+
if topic == "" {
213+
t.Fatal("RunYAMLTests: trigger.name (topic) is required for event triggers")
214+
}
215+
return h.FireEvent(topic, tc.Trigger.Data)
216+
203217
default:
204218
t.Fatalf("RunYAMLTests: unsupported trigger type %q", tc.Trigger.Type)
205219
return nil

wftest/yaml_runner_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,121 @@ func TestYAMLRunner_StatefulTestData(t *testing.T) {
221221
wftest.RunYAMLTests(t, "testdata/stateful_test.yaml")
222222
}
223223

224+
func TestRunYAMLTests_ScheduleTrigger(t *testing.T) {
225+
tmpDir := t.TempDir()
226+
writeFile(t, tmpDir+"/schedule_test.yaml", `
227+
yaml: |
228+
pipelines:
229+
cleanup-sessions:
230+
steps:
231+
- name: run
232+
type: step.set
233+
config:
234+
values:
235+
status: completed
236+
tests:
237+
cleanup-job:
238+
trigger:
239+
type: schedule
240+
name: cleanup-sessions
241+
assertions:
242+
- output:
243+
status: completed
244+
`)
245+
wftest.RunYAMLTests(t, tmpDir+"/schedule_test.yaml")
246+
}
247+
248+
func TestRunYAMLTests_ScheduleTriggerWithData(t *testing.T) {
249+
tmpDir := t.TempDir()
250+
writeFile(t, tmpDir+"/schedule_data_test.yaml", `
251+
yaml: |
252+
pipelines:
253+
parameterized-job:
254+
steps:
255+
- name: echo
256+
type: step.set
257+
config:
258+
values:
259+
got: "{{ .param1 }}"
260+
tests:
261+
job-with-params:
262+
trigger:
263+
type: schedule
264+
name: parameterized-job
265+
data:
266+
param1: value1
267+
assertions:
268+
- output:
269+
got: value1
270+
`)
271+
wftest.RunYAMLTests(t, tmpDir+"/schedule_data_test.yaml")
272+
}
273+
274+
func TestRunYAMLTests_EventTrigger(t *testing.T) {
275+
tmpDir := t.TempDir()
276+
writeFile(t, tmpDir+"/event_test.yaml", `
277+
yaml: |
278+
pipelines:
279+
on-submission:
280+
trigger:
281+
type: eventbus
282+
config:
283+
topic: forms.submission.created
284+
steps:
285+
- name: process
286+
type: step.set
287+
config:
288+
values:
289+
handled: true
290+
form_id: "{{ .form_id }}"
291+
tests:
292+
submission-event:
293+
trigger:
294+
type: event
295+
name: forms.submission.created
296+
data:
297+
affiliate_id: sampleaff1
298+
form_id: form-uuid-1
299+
assertions:
300+
- output:
301+
handled: true
302+
form_id: form-uuid-1
303+
`)
304+
wftest.RunYAMLTests(t, tmpDir+"/event_test.yaml")
305+
}
306+
307+
func TestRunYAMLTests_EventbusTriggerAlias(t *testing.T) {
308+
tmpDir := t.TempDir()
309+
writeFile(t, tmpDir+"/eventbus_test.yaml", `
310+
yaml: |
311+
pipelines:
312+
on-user-created:
313+
trigger:
314+
type: eventbus
315+
config:
316+
topic: user.created
317+
steps:
318+
- name: log_event
319+
type: step.set
320+
config:
321+
values:
322+
handled: true
323+
user_id: "{{ .user_id }}"
324+
tests:
325+
user-created:
326+
trigger:
327+
type: eventbus
328+
name: user.created
329+
data:
330+
user_id: "123"
331+
assertions:
332+
- output:
333+
handled: true
334+
user_id: "123"
335+
`)
336+
wftest.RunYAMLTests(t, tmpDir+"/eventbus_test.yaml")
337+
}
338+
224339
func writeFile(t *testing.T, path, content string) {
225340
t.Helper()
226341
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {

0 commit comments

Comments
 (0)