|
| 1 | +use std::process::Command; |
| 2 | + |
| 3 | +use tempfile::tempdir; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn github_uninstall_rejects_unrelated_workflow_mentioning_cortex() { |
| 7 | + let repo_dir = tempdir().unwrap(); |
| 8 | + let workflows_dir = repo_dir.path().join(".github").join("workflows"); |
| 9 | + std::fs::create_dir_all(&workflows_dir).unwrap(); |
| 10 | + let workflow_path = workflows_dir.join("ci.yml"); |
| 11 | + std::fs::write( |
| 12 | + &workflow_path, |
| 13 | + r#"name: CI |
| 14 | +on: [push] |
| 15 | +# notify cortex team on failure |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - run: echo unrelated |
| 21 | +"#, |
| 22 | + ) |
| 23 | + .unwrap(); |
| 24 | + |
| 25 | + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) |
| 26 | + .args([ |
| 27 | + "github", |
| 28 | + "uninstall", |
| 29 | + "--path", |
| 30 | + repo_dir.path().to_str().unwrap(), |
| 31 | + "--workflow-name", |
| 32 | + "ci", |
| 33 | + "--force", |
| 34 | + ]) |
| 35 | + .output() |
| 36 | + .unwrap(); |
| 37 | + |
| 38 | + let stderr = String::from_utf8_lossy(&output.stderr); |
| 39 | + assert!(!output.status.success()); |
| 40 | + assert!( |
| 41 | + stderr.contains("Cortex workflow 'ci' not found"), |
| 42 | + "unexpected stderr: {stderr}" |
| 43 | + ); |
| 44 | + assert!(workflow_path.exists(), "unrelated workflow was deleted"); |
| 45 | +} |
| 46 | + |
| 47 | +#[test] |
| 48 | +fn github_uninstall_removes_generated_workflow() { |
| 49 | + let repo_dir = tempdir().unwrap(); |
| 50 | + let workflows_dir = repo_dir.path().join(".github").join("workflows"); |
| 51 | + std::fs::create_dir_all(&workflows_dir).unwrap(); |
| 52 | + let workflow_path = workflows_dir.join("Cortex.yml"); |
| 53 | + std::fs::write( |
| 54 | + &workflow_path, |
| 55 | + r#"# Cortex CI/CD Automation |
| 56 | +# Generated by: cortex github install |
| 57 | +name: Cortex |
| 58 | +"#, |
| 59 | + ) |
| 60 | + .unwrap(); |
| 61 | + |
| 62 | + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) |
| 63 | + .args([ |
| 64 | + "github", |
| 65 | + "uninstall", |
| 66 | + "--path", |
| 67 | + repo_dir.path().to_str().unwrap(), |
| 68 | + "--workflow-name", |
| 69 | + "Cortex", |
| 70 | + "--force", |
| 71 | + ]) |
| 72 | + .output() |
| 73 | + .unwrap(); |
| 74 | + |
| 75 | + let stderr = String::from_utf8_lossy(&output.stderr); |
| 76 | + assert!(output.status.success(), "unexpected stderr: {stderr}"); |
| 77 | + assert!( |
| 78 | + !workflow_path.exists(), |
| 79 | + "generated workflow was not deleted" |
| 80 | + ); |
| 81 | +} |
0 commit comments