(t *testing.T)
| 165 | } |
| 166 | |
| 167 | func TestFixCommand_NetworkFirewallMigration(t *testing.T) { |
| 168 | // Create a temporary directory for test files |
| 169 | tmpDir := t.TempDir() |
| 170 | workflowFile := filepath.Join(tmpDir, "test-workflow.md") |
| 171 | |
| 172 | // Create a workflow with deprecated network.firewall field |
| 173 | content := `--- |
| 174 | on: |
| 175 | workflow_dispatch: |
| 176 | |
| 177 | network: |
| 178 | allowed: |
| 179 | - "*.example.com" |
| 180 | firewall: null |
| 181 | |
| 182 | permissions: |
| 183 | contents: read |
| 184 | --- |
| 185 | |
| 186 | # Test Workflow |
| 187 | |
| 188 | This is a test workflow. |
| 189 | ` |
| 190 | |
| 191 | if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil { |
| 192 | t.Fatalf("Failed to create test file: %v", err) |
| 193 | } |
| 194 | |
| 195 | // Get the firewall migration codemod |
| 196 | firewallCodemod := getCodemodByID("network-firewall-migration") |
| 197 | if firewallCodemod == nil { |
| 198 | t.Fatal("network-firewall-migration codemod not found") |
| 199 | } |
| 200 | |
| 201 | // Process the file |
| 202 | fixed, _, err := processWorkflowFileWithInfo(workflowFile, []Codemod{*firewallCodemod}, true, false) |
| 203 | if err != nil { |
| 204 | t.Fatalf("Failed to process workflow file: %v", err) |
| 205 | } |
| 206 | |
| 207 | if !fixed { |
| 208 | t.Error("Expected file to be fixed, but no changes were made") |
| 209 | } |
| 210 | |
| 211 | // Read the updated content |
| 212 | updatedContent, err := os.ReadFile(workflowFile) |
| 213 | if err != nil { |
| 214 | t.Fatalf("Failed to read updated file: %v", err) |
| 215 | } |
| 216 | |
| 217 | updatedStr := string(updatedContent) |
| 218 | |
| 219 | // Verify the change |
| 220 | if strings.Contains(updatedStr, "firewall:") { |
| 221 | t.Error("Expected firewall field to be removed, but it still exists") |
| 222 | } |
| 223 | |
| 224 | if !strings.Contains(updatedStr, "sandbox:") { |
nothing calls this directly
no test coverage detected