(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestGitHubAppClientIDCodemod(t *testing.T) { |
| 13 | codemod := getGitHubAppClientIDCodemod() |
| 14 | |
| 15 | t.Run("renames app-id under github-app blocks", func(t *testing.T) { |
| 16 | content := `--- |
| 17 | github-app: |
| 18 | app-id: ${{ vars.TOP_LEVEL_APP_ID }} |
| 19 | private-key: ${{ secrets.TOP_LEVEL_APP_PRIVATE_KEY }} |
| 20 | on: |
| 21 | github-app: |
| 22 | app-id: ${{ vars.ACTIVATION_APP_ID }} |
| 23 | private-key: ${{ secrets.ACTIVATION_APP_PRIVATE_KEY }} |
| 24 | checkout: |
| 25 | - repository: org/repo |
| 26 | github-app: |
| 27 | app-id: ${{ vars.CHECKOUT_APP_ID }} |
| 28 | private-key: ${{ secrets.CHECKOUT_APP_PRIVATE_KEY }} |
| 29 | --- |
| 30 | ` |
| 31 | frontmatter := map[string]any{ |
| 32 | "github-app": map[string]any{ |
| 33 | "app-id": "${{ vars.TOP_LEVEL_APP_ID }}", |
| 34 | "private-key": "${{ secrets.TOP_LEVEL_APP_PRIVATE_KEY }}", |
| 35 | }, |
| 36 | "on": map[string]any{ |
| 37 | "github-app": map[string]any{ |
| 38 | "app-id": "${{ vars.ACTIVATION_APP_ID }}", |
| 39 | "private-key": "${{ secrets.ACTIVATION_APP_PRIVATE_KEY }}", |
| 40 | }, |
| 41 | }, |
| 42 | "checkout": []any{ |
| 43 | map[string]any{ |
| 44 | "repository": "org/repo", |
| 45 | "github-app": map[string]any{ |
| 46 | "app-id": "${{ vars.CHECKOUT_APP_ID }}", |
| 47 | "private-key": "${{ secrets.CHECKOUT_APP_PRIVATE_KEY }}", |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | result, modified, err := codemod.Apply(content, frontmatter) |
| 54 | require.NoError(t, err, "Should not error when applying codemod") |
| 55 | assert.True(t, modified, "Should modify content") |
| 56 | assert.NotContains(t, result, "app-id:", "Should remove deprecated app-id key from github-app blocks") |
| 57 | assert.Contains(t, result, "client-id: ${{ vars.TOP_LEVEL_APP_ID }}", "Should migrate top-level github-app") |
| 58 | assert.Contains(t, result, "client-id: ${{ vars.ACTIVATION_APP_ID }}", "Should migrate on.github-app") |
| 59 | assert.Contains(t, result, "client-id: ${{ vars.CHECKOUT_APP_ID }}", "Should migrate checkout github-app") |
| 60 | }) |
| 61 | |
| 62 | t.Run("does not modify content without github-app.app-id", func(t *testing.T) { |
| 63 | content := `--- |
| 64 | github-app: |
| 65 | client-id: ${{ vars.APP_ID }} |
| 66 | private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 67 | --- |
| 68 | ` |
| 69 | frontmatter := map[string]any{ |
nothing calls this directly
no test coverage detected