(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func TestEnsureMaintenanceWorkflow(t *testing.T) { |
| 176 | tests := []struct { |
| 177 | name string |
| 178 | setupWorkflows bool |
| 179 | workflowsWithExpires bool |
| 180 | expectMaintenanceFile bool |
| 181 | expectMaintenanceDelete bool |
| 182 | }{ |
| 183 | { |
| 184 | name: "generates maintenance workflow when expires field present", |
| 185 | setupWorkflows: true, |
| 186 | workflowsWithExpires: true, |
| 187 | expectMaintenanceFile: true, |
| 188 | }, |
| 189 | { |
| 190 | name: "deletes maintenance workflow when no expires field", |
| 191 | setupWorkflows: true, |
| 192 | workflowsWithExpires: false, |
| 193 | expectMaintenanceDelete: true, |
| 194 | }, |
| 195 | { |
| 196 | name: "skips when no workflows directory", |
| 197 | setupWorkflows: false, |
| 198 | expectMaintenanceFile: false, |
| 199 | }, |
| 200 | } |
| 201 | |
| 202 | for _, tt := range tests { |
| 203 | t.Run(tt.name, func(t *testing.T) { |
| 204 | // Create a temporary directory for testing |
| 205 | tempDir := testutil.TempDir(t, "test-maintenance-*") |
| 206 | |
| 207 | // Change to temp directory |
| 208 | oldWd, err := os.Getwd() |
| 209 | if err != nil { |
| 210 | t.Fatalf("Failed to get current directory: %v", err) |
| 211 | } |
| 212 | defer func() { |
| 213 | _ = os.Chdir(oldWd) |
| 214 | }() |
| 215 | err = os.Chdir(tempDir) |
| 216 | if err != nil { |
| 217 | t.Fatalf("Failed to change directory: %v", err) |
| 218 | } |
| 219 | |
| 220 | // Initialize git repo |
| 221 | if err := exec.Command("git", "init").Run(); err != nil { |
| 222 | t.Fatalf("Failed to init git repo: %v", err) |
| 223 | } |
| 224 | |
| 225 | maintenanceFile := filepath.Join(tempDir, ".github", "workflows", "agentics-maintenance.yml") |
| 226 | |
| 227 | // Setup workflows if needed |
| 228 | if tt.setupWorkflows { |
| 229 | workflowsDir := filepath.Join(tempDir, ".github", "workflows") |
| 230 | if err := os.MkdirAll(workflowsDir, 0755); err != nil { |
| 231 | t.Fatalf("Failed to create workflows directory: %v", err) |
| 232 | } |
nothing calls this directly
no test coverage detected