TestAddEngineToWorkflow tests the addEngineToWorkflow function
(t *testing.T)
| 182 | |
| 183 | // TestAddEngineToWorkflow tests the addEngineToWorkflow function |
| 184 | func TestAddEngineToWorkflow(t *testing.T) { |
| 185 | tests := []struct { |
| 186 | name string |
| 187 | content string |
| 188 | engine string |
| 189 | expectError bool |
| 190 | checkEngine bool |
| 191 | expectBlankLine bool // expect blank line after engine declaration |
| 192 | }{ |
| 193 | { |
| 194 | name: "add_new_engine_field_has_trailing_blank_line", |
| 195 | content: `--- |
| 196 | on: push |
| 197 | permissions: |
| 198 | contents: read |
| 199 | --- |
| 200 | |
| 201 | # Test Workflow`, |
| 202 | engine: "claude", |
| 203 | expectError: false, |
| 204 | checkEngine: true, |
| 205 | expectBlankLine: true, |
| 206 | }, |
| 207 | { |
| 208 | name: "update_existing_engine_field_no_extra_blank_line", |
| 209 | content: `--- |
| 210 | on: push |
| 211 | engine: codex |
| 212 | --- |
| 213 | |
| 214 | # Test Workflow`, |
| 215 | engine: "claude", |
| 216 | expectError: false, |
| 217 | checkEngine: true, |
| 218 | expectBlankLine: false, // updating existing field doesn't add a blank line |
| 219 | }, |
| 220 | } |
| 221 | |
| 222 | for _, tt := range tests { |
| 223 | t.Run(tt.name, func(t *testing.T) { |
| 224 | result, err := addEngineToWorkflow(tt.content, tt.engine) |
| 225 | |
| 226 | if tt.expectError && err == nil { |
| 227 | t.Errorf("addEngineToWorkflow() expected error, got nil") |
| 228 | return |
| 229 | } |
| 230 | |
| 231 | if !tt.expectError && err != nil { |
| 232 | t.Errorf("addEngineToWorkflow() error = %v", err) |
| 233 | return |
| 234 | } |
| 235 | |
| 236 | if !tt.expectError && tt.checkEngine { |
| 237 | // Verify that the engine field is present with the correct value |
| 238 | if !strings.Contains(result, "engine: "+tt.engine) { |
| 239 | t.Errorf("addEngineToWorkflow() result does not contain 'engine: %s'. Result:\n%s", tt.engine, result) |
| 240 | } |
| 241 |
nothing calls this directly
no test coverage detected