MCPcopy Create free account
hub / github.com/github/gh-aw / TestFixCommand_AppToGitHubAppMigration

Function TestFixCommand_AppToGitHubAppMigration

pkg/cli/fix_command_test.go:945–1007  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

943}
944
945func 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 := `---
951on:
952 workflow_dispatch:
953
954engine: copilot
955app:
956 app-id: ${{ vars.APP_ID }}
957 private-key: ${{ secrets.APP_PRIVATE_KEY }}
958
959permissions:
960 contents: read
961---
962
963# Test Workflow
964
965This 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 }

Callers

nothing calls this directly

Calls 3

getCodemodByIDFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected