TestGetGitHubToken tests the GetGitHubToken function environment variable precedence.
(t *testing.T)
| 57 | |
| 58 | // TestGetGitHubToken tests the GetGitHubToken function environment variable precedence. |
| 59 | func TestGetGitHubToken(t *testing.T) { |
| 60 | // Test precedence: DDEV_GITHUB_TOKEN > GH_TOKEN > GITHUB_TOKEN |
| 61 | t.Run("Precedence", func(t *testing.T) { |
| 62 | // Clean environment |
| 63 | t.Setenv("DDEV_GITHUB_TOKEN", "") |
| 64 | t.Setenv("GH_TOKEN", "") |
| 65 | t.Setenv("GITHUB_TOKEN", "") |
| 66 | |
| 67 | // Test no tokens returns empty |
| 68 | token, _ := github.GetGitHubToken() |
| 69 | require.Empty(t, token, "Should return empty when no tokens set") |
| 70 | |
| 71 | // Test GITHUB_TOKEN only |
| 72 | t.Setenv("GITHUB_TOKEN", "github_token_value") |
| 73 | token, _ = github.GetGitHubToken() |
| 74 | require.Equal(t, "github_token_value", token, "Should return GITHUB_TOKEN when it's the only one set") |
| 75 | |
| 76 | // Test GH_TOKEN overrides GITHUB_TOKEN |
| 77 | t.Setenv("GH_TOKEN", "gh_token_value") |
| 78 | token, _ = github.GetGitHubToken() |
| 79 | require.Equal(t, "gh_token_value", token, "Should return GH_TOKEN when both GH_TOKEN and GITHUB_TOKEN are set") |
| 80 | |
| 81 | // Test DDEV_GITHUB_TOKEN has the highest precedence |
| 82 | t.Setenv("DDEV_GITHUB_TOKEN", "ddev_token_value") |
| 83 | token, _ = github.GetGitHubToken() |
| 84 | require.Equal(t, "ddev_token_value", token, "Should return DDEV_GITHUB_TOKEN when all tokens are set") |
| 85 | }) |
| 86 | } |
| 87 | |
| 88 | // TestGetGitHubHeaders tests the GetGitHubHeaders function URL filtering. |
| 89 | func TestGetGitHubHeaders(t *testing.T) { |
nothing calls this directly
no test coverage detected