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

Function TestWriteWorkflowOutput

pkg/workflow/compiler_test.go:751–820  ·  view source on GitHub ↗

TestWriteWorkflowOutput tests the writeWorkflowOutput function

(t *testing.T)

Source from the content-addressed store, hash-verified

749
750// TestWriteWorkflowOutput tests the writeWorkflowOutput function
751func TestWriteWorkflowOutput(t *testing.T) {
752 tests := []struct {
753 name string
754 yamlContent string
755 noEmit bool
756 quiet bool
757 shouldError bool
758 expectFileWritten bool
759 }{
760 {
761 name: "write valid YAML",
762 yamlContent: "name: test\non: push\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo test\n",
763 noEmit: false,
764 quiet: false,
765 shouldError: false,
766 expectFileWritten: true,
767 },
768 {
769 name: "no emit mode",
770 yamlContent: "name: test\non: push\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo test\n",
771 noEmit: true,
772 quiet: false,
773 shouldError: false,
774 expectFileWritten: false,
775 },
776 {
777 name: "quiet mode",
778 yamlContent: "name: test\non: push\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo test\n",
779 noEmit: false,
780 quiet: true,
781 shouldError: false,
782 expectFileWritten: true,
783 },
784 }
785
786 for _, tt := range tests {
787 t.Run(tt.name, func(t *testing.T) {
788 tmpDir := testutil.TempDir(t, "output-test")
789 markdownPath := filepath.Join(tmpDir, "test.md")
790 lockFile := stringutil.MarkdownToLockFile(markdownPath)
791
792 compiler := NewCompiler()
793 compiler.noEmit = tt.noEmit
794 compiler.quiet = tt.quiet
795
796 err := compiler.writeWorkflowOutput(lockFile, tt.yamlContent, markdownPath)
797
798 if tt.shouldError {
799 require.Error(t, err, "Expected write to fail")
800 } else {
801 require.NoError(t, err, "Expected write to pass")
802
803 if tt.expectFileWritten {
804 // Verify file was created
805 _, err := os.Stat(lockFile)
806 require.NoError(t, err, "Lock file should be created")
807
808 // Verify content

Callers

nothing calls this directly

Calls 6

writeWorkflowOutputMethod · 0.95
TempDirFunction · 0.92
MarkdownToLockFileFunction · 0.92
NewCompilerFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected