TestUpgradeCopilotSetupSteps tests upgrading version in existing copilot-setup-steps.yml
(t *testing.T)
| 890 | |
| 891 | // TestUpgradeCopilotSetupSteps tests upgrading version in existing copilot-setup-steps.yml |
| 892 | func TestUpgradeCopilotSetupSteps(t *testing.T) { |
| 893 | tmpDir := t.TempDir() |
| 894 | originalDir, err := os.Getwd() |
| 895 | if err != nil { |
| 896 | t.Fatalf("Failed to get current directory: %v", err) |
| 897 | } |
| 898 | defer func() { _ = os.Chdir(originalDir) }() |
| 899 | |
| 900 | if err := os.Chdir(tmpDir); err != nil { |
| 901 | t.Fatalf("Failed to change to temp directory: %v", err) |
| 902 | } |
| 903 | |
| 904 | // Create .github/workflows directory |
| 905 | workflowsDir := filepath.Join(".github", "workflows") |
| 906 | if err := os.MkdirAll(workflowsDir, 0755); err != nil { |
| 907 | t.Fatalf("Failed to create workflows directory: %v", err) |
| 908 | } |
| 909 | |
| 910 | // Write existing workflow WITH actions/setup-cli at v1.0.0 |
| 911 | existingContent := `name: "Copilot Setup Steps" |
| 912 | on: workflow_dispatch |
| 913 | jobs: |
| 914 | copilot-setup-steps: |
| 915 | runs-on: ubuntu-latest |
| 916 | steps: |
| 917 | - name: Checkout repository |
| 918 | uses: actions/checkout@v4 |
| 919 | - name: Install gh-aw extension |
| 920 | uses: github/gh-aw-actions/setup-cli@v1.0.0 |
| 921 | with: |
| 922 | version: v1.0.0 |
| 923 | - name: Verify gh-aw installation |
| 924 | run: gh aw version |
| 925 | ` |
| 926 | setupStepsPath := filepath.Join(workflowsDir, "copilot-setup-steps.yml") |
| 927 | if err := os.WriteFile(setupStepsPath, []byte(existingContent), 0644); err != nil { |
| 928 | t.Fatalf("Failed to write existing workflow: %v", err) |
| 929 | } |
| 930 | |
| 931 | // Upgrade to v2.0.0 |
| 932 | err = upgradeCopilotSetupSteps(context.Background(), false, workflow.ActionModeRelease, "v2.0.0") |
| 933 | if err != nil { |
| 934 | t.Fatalf("upgradeCopilotSetupSteps(context.Background()) failed: %v", err) |
| 935 | } |
| 936 | |
| 937 | // Read updated file |
| 938 | content, err := os.ReadFile(setupStepsPath) |
| 939 | if err != nil { |
| 940 | t.Fatalf("Failed to read updated file: %v", err) |
| 941 | } |
| 942 | |
| 943 | contentStr := string(content) |
| 944 | |
| 945 | // Verify version was upgraded |
| 946 | if !strings.Contains(contentStr, "actions/setup-cli@v2.0.0") { |
| 947 | t.Errorf("Expected action reference to be upgraded to @v2.0.0, got:\n%s", contentStr) |
| 948 | } |
| 949 | if !strings.Contains(contentStr, "version: v2.0.0") { |
nothing calls this directly
no test coverage detected