TestExtractWorkflowDescriptionFromFile tests the ExtractWorkflowDescriptionFromFile function
(t *testing.T)
| 99 | |
| 100 | // TestExtractWorkflowDescriptionFromFile tests the ExtractWorkflowDescriptionFromFile function |
| 101 | func TestExtractWorkflowDescriptionFromFile(t *testing.T) { |
| 102 | tests := []struct { |
| 103 | name string |
| 104 | content string |
| 105 | expected string |
| 106 | }{ |
| 107 | { |
| 108 | name: "file with description", |
| 109 | content: `--- |
| 110 | name: Test Workflow |
| 111 | description: This is a test workflow description from file |
| 112 | on: push |
| 113 | --- |
| 114 | |
| 115 | # Test Workflow |
| 116 | |
| 117 | This is the workflow content.`, |
| 118 | expected: "This is a test workflow description from file", |
| 119 | }, |
| 120 | { |
| 121 | name: "file without description", |
| 122 | content: `--- |
| 123 | name: Test Workflow |
| 124 | on: push |
| 125 | --- |
| 126 | |
| 127 | # Test Workflow`, |
| 128 | expected: "", |
| 129 | }, |
| 130 | } |
| 131 | |
| 132 | for _, tt := range tests { |
| 133 | t.Run(tt.name, func(t *testing.T) { |
| 134 | // Create temporary file |
| 135 | tmpFile := testutil.TempDir(t, "test-*") + "/test-workflow.md" |
| 136 | if err := os.WriteFile(tmpFile, []byte(tt.content), 0644); err != nil { |
| 137 | t.Fatalf("Failed to create temp file: %v", err) |
| 138 | } |
| 139 | |
| 140 | result := ExtractWorkflowDescriptionFromFile(tmpFile) |
| 141 | if result != tt.expected { |
| 142 | t.Errorf("ExtractWorkflowDescriptionFromFile() = %q, want %q", result, tt.expected) |
| 143 | } |
| 144 | }) |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // TestExtractWorkflowDescriptionFromFile_NonExistentFile tests handling of non-existent files |
| 149 | func TestExtractWorkflowDescriptionFromFile_NonExistentFile(t *testing.T) { |
nothing calls this directly
no test coverage detected