(t *testing.T)
| 228 | } |
| 229 | |
| 230 | func TestCheckWorkflowFileStatus(t *testing.T) { |
| 231 | tmpDir := testutil.TempDir(t, "test-*") |
| 232 | |
| 233 | originalDir, err := os.Getwd() |
| 234 | require.NoError(t, err, "get current directory for test setup") |
| 235 | defer func() { |
| 236 | _ = os.Chdir(originalDir) |
| 237 | }() |
| 238 | |
| 239 | require.NoError(t, os.Chdir(tmpDir), "change to temp directory for test setup") |
| 240 | |
| 241 | // Initialize git repo |
| 242 | if err := exec.Command("git", "init").Run(); err != nil { |
| 243 | t.Skip("Git not available") |
| 244 | } |
| 245 | |
| 246 | // Configure git |
| 247 | exec.Command("git", "config", "user.name", "Test User").Run() |
| 248 | exec.Command("git", "config", "user.email", "test@example.com").Run() |
| 249 | |
| 250 | // Create .github/workflows directory |
| 251 | workflowDir := ".github/workflows" |
| 252 | require.NoError(t, os.MkdirAll(workflowDir, 0755), "create workflow directory") |
| 253 | |
| 254 | workflowFile := ".github/workflows/test.md" |
| 255 | |
| 256 | // Test 1: File doesn't exist - should return empty status |
| 257 | t.Run("file_not_tracked", func(t *testing.T) { |
| 258 | status, err := checkWorkflowFileStatus(workflowFile) |
| 259 | require.NoError(t, err, "get workflow file status for untracked file") |
| 260 | assert.False(t, status.IsModified, "untracked file should not be marked modified") |
| 261 | assert.False(t, status.IsStaged, "untracked file should not be marked staged") |
| 262 | assert.False(t, status.HasUnpushedCommits, "untracked file should not report unpushed commits") |
| 263 | }) |
| 264 | |
| 265 | // Create and commit a workflow file |
| 266 | require.NoError(t, os.WriteFile(workflowFile, []byte("# Test Workflow\n"), 0644), "create workflow file") |
| 267 | exec.Command("git", "add", workflowFile).Run() |
| 268 | if err := exec.Command("git", "commit", "-m", "Add workflow").Run(); err != nil { |
| 269 | t.Skip("Failed to create initial commit") |
| 270 | } |
| 271 | |
| 272 | // Test 2: Clean file - no changes |
| 273 | t.Run("clean_file", func(t *testing.T) { |
| 274 | status, err := checkWorkflowFileStatus(workflowFile) |
| 275 | require.NoError(t, err, "get workflow file status for clean file") |
| 276 | assert.False(t, status.IsModified, "clean file should not be marked modified") |
| 277 | assert.False(t, status.IsStaged, "clean file should not be marked staged") |
| 278 | assert.False(t, status.HasUnpushedCommits, "clean file should not report unpushed commits") |
| 279 | }) |
| 280 | |
| 281 | // Test 3: Modified file (unstaged changes) |
| 282 | t.Run("modified_file", func(t *testing.T) { |
| 283 | require.NoError(t, os.WriteFile(workflowFile, []byte("# Modified Workflow\n"), 0644), "modify workflow file") |
| 284 | |
| 285 | status, err := checkWorkflowFileStatus(workflowFile) |
| 286 | require.NoError(t, err, "get workflow file status for modified file") |
| 287 | assert.True(t, status.IsModified, "modified file should be marked modified") |
nothing calls this directly
no test coverage detected