MCPcopy Create free account
hub / github.com/github/gh-aw / FuzzTriggerIRToYAMLMap

Function FuzzTriggerIRToYAMLMap

pkg/workflow/trigger_parser_fuzz_test.go:241–300  ·  view source on GitHub ↗

FuzzTriggerIRToYAMLMap is a fuzz test for the ToYAMLMap method. It validates that the YAML map generation handles various IR structures correctly.

(f *testing.F)

Source from the content-addressed store, hash-verified

239// FuzzTriggerIRToYAMLMap is a fuzz test for the ToYAMLMap method.
240// It validates that the YAML map generation handles various IR structures correctly.
241func FuzzTriggerIRToYAMLMap(f *testing.F) {
242 // Seed with valid IR structures
243 f.Add("push", "")
244 f.Add("pull_request", "opened,synchronize")
245 f.Add("issues", "opened")
246 f.Add("discussion", "created")
247 f.Add("release", "published")
248 f.Add("watch", "started")
249 f.Add("fork", "")
250 f.Add("issue_comment", "created")
251 f.Add("workflow_run", "completed")
252 f.Add("repository_dispatch", "")
253 f.Add("code_scanning_alert", "created")
254
255 f.Fuzz(func(t *testing.T, event string, typesStr string) {
256 // Parse types from comma-separated string
257 var types []string
258 if typesStr != "" {
259 for typ := range strings.SplitSeq(typesStr, ",") {
260 typ = strings.TrimSpace(typ)
261 if typ != "" {
262 types = append(types, typ)
263 }
264 }
265 }
266
267 // Create IR
268 ir := &TriggerIR{
269 Event: event,
270 Types: types,
271 Filters: map[string]any{
272 "branches": []string{"main"},
273 },
274 AdditionalEvents: map[string]any{
275 "workflow_dispatch": nil,
276 },
277 }
278
279 // ToYAMLMap should never panic
280 result := ir.ToYAMLMap()
281
282 // Validate result structure
283 if result == nil {
284 t.Error("ToYAMLMap returned nil")
285 return
286 }
287
288 // If event is non-empty, it should be in the result
289 if event != "" {
290 if _, hasEvent := result[event]; !hasEvent {
291 t.Errorf("ToYAMLMap result missing event %q", event)
292 }
293 }
294
295 // Additional events should be present
296 if _, hasDispatch := result["workflow_dispatch"]; !hasDispatch {
297 t.Error("ToYAMLMap result missing workflow_dispatch")
298 }

Callers

nothing calls this directly

Calls 4

ToYAMLMapMethod · 0.95
AddMethod · 0.45
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected