(t *testing.T)
| 943 | } |
| 944 | |
| 945 | func TestFixCommand_AppToGitHubAppMigration(t *testing.T) { |
| 946 | // Create a temporary directory for test files |
| 947 | tmpDir := t.TempDir() |
| 948 | workflowFile := filepath.Join(tmpDir, "test-workflow.md") |
| 949 | |
| 950 | content := `--- |
| 951 | on: |
| 952 | workflow_dispatch: |
| 953 | |
| 954 | engine: copilot |
| 955 | app: |
| 956 | app-id: ${{ vars.APP_ID }} |
| 957 | private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 958 | |
| 959 | permissions: |
| 960 | contents: read |
| 961 | --- |
| 962 | |
| 963 | # Test Workflow |
| 964 | |
| 965 | This workflow uses top-level app auth. |
| 966 | ` |
| 967 | |
| 968 | if err := os.WriteFile(workflowFile, []byte(content), 0644); err != nil { |
| 969 | t.Fatalf("Failed to create test file: %v", err) |
| 970 | } |
| 971 | |
| 972 | appCodemod := getCodemodByID("app-to-github-app") |
| 973 | if appCodemod == nil { |
| 974 | t.Fatal("app-to-github-app codemod not found") |
| 975 | } |
| 976 | |
| 977 | fixed, _, err := processWorkflowFileWithInfo(workflowFile, []Codemod{*appCodemod}, true, false) |
| 978 | if err != nil { |
| 979 | t.Fatalf("Failed to process workflow file: %v", err) |
| 980 | } |
| 981 | |
| 982 | if !fixed { |
| 983 | t.Error("Expected file to be modified") |
| 984 | } |
| 985 | |
| 986 | updated, err := os.ReadFile(workflowFile) |
| 987 | if err != nil { |
| 988 | t.Fatalf("Failed to read updated file: %v", err) |
| 989 | } |
| 990 | updatedStr := string(updated) |
| 991 | |
| 992 | if strings.Contains(updatedStr, "\napp:\n") { |
| 993 | t.Error("Expected top-level 'app:' to be removed") |
| 994 | } |
| 995 | |
| 996 | if !strings.Contains(updatedStr, "\ngithub-app:\n") { |
| 997 | t.Error("Expected top-level 'github-app:' to be added") |
| 998 | } |
| 999 | |
| 1000 | if !strings.Contains(updatedStr, "# Test Workflow") { |
| 1001 | t.Error("Expected markdown heading to be preserved") |
| 1002 | } |
nothing calls this directly
no test coverage detected