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

Function TestConclusionJobSafeOutputsResult

pkg/workflow/notify_comment_test.go:323–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

321}
322
323func TestConclusionJobSafeOutputsResult(t *testing.T) {
324 // Test that GH_AW_SAFE_OUTPUTS_RESULT env var is emitted when safe_outputs is in safeOutputJobNames
325 compiler := NewCompiler()
326 statusCommentTrue := true
327 workflowData := &WorkflowData{
328 Name: "Test Workflow",
329 AIReaction: "eyes",
330 StatusComment: &statusCommentTrue,
331 SafeOutputs: &SafeOutputsConfig{
332 AddComments: &AddCommentsConfig{
333 BaseSafeOutputConfig: BaseSafeOutputConfig{
334 Max: strPtr("1"),
335 },
336 },
337 },
338 }
339
340 tests := []struct {
341 name string
342 safeOutputJobNames []string
343 expectEnvVar bool
344 }{
345 {
346 name: "GH_AW_SAFE_OUTPUTS_RESULT present when safe_outputs is in job list",
347 safeOutputJobNames: []string{"safe_outputs", "add_comment"},
348 expectEnvVar: true,
349 },
350 {
351 name: "GH_AW_SAFE_OUTPUTS_RESULT absent when safe_outputs is not in job list",
352 safeOutputJobNames: []string{"add_comment"},
353 expectEnvVar: false,
354 },
355 }
356
357 for _, tt := range tests {
358 t.Run(tt.name, func(t *testing.T) {
359 job, err := compiler.buildConclusionJob(workflowData, string(constants.AgentJobName), tt.safeOutputJobNames)
360 if err != nil {
361 t.Fatalf("Failed to build conclusion job: %v", err)
362 }
363 if job == nil {
364 t.Fatal("Expected conclusion job to be created")
365 }
366
367 jobYAML := strings.Join(job.Steps, "")
368 envVarDeclaration := "GH_AW_SAFE_OUTPUTS_RESULT: ${{ needs.safe_outputs.result }}"
369 hasEnvVar := strings.Contains(jobYAML, envVarDeclaration)
370
371 if tt.expectEnvVar && !hasEnvVar {
372 t.Errorf("Expected GH_AW_SAFE_OUTPUTS_RESULT env var when safe_outputs is in job list, but it was missing")
373 }
374 if !tt.expectEnvVar && hasEnvVar {
375 t.Errorf("Did not expect GH_AW_SAFE_OUTPUTS_RESULT env var when safe_outputs is not in job list, but it was present")
376 }
377 })
378 }
379}
380

Callers

nothing calls this directly

Calls 5

buildConclusionJobMethod · 0.95
NewCompilerFunction · 0.85
strPtrFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected