MCPcopy Create free account
hub / github.com/ddev/ddev / TestGetGitHubHeaders

Function TestGetGitHubHeaders

pkg/github/github_test.go:89–129  ·  view source on GitHub ↗

TestGetGitHubHeaders tests the GetGitHubHeaders function URL filtering.

(t *testing.T)

Source from the content-addressed store, hash-verified

87
88// TestGetGitHubHeaders tests the GetGitHubHeaders function URL filtering.
89func TestGetGitHubHeaders(t *testing.T) {
90 t.Run("GitHubURLs", func(t *testing.T) {
91 t.Setenv("DDEV_GITHUB_TOKEN", "test_token")
92
93 // Test https://github.com URLs
94 headers := github.GetGitHubHeaders("https://github.com/owner/repo")
95 require.Equal(t, "Bearer test_token", headers["Authorization"], "Should include auth header for https://github.com")
96 require.Equal(t, "2022-11-28", headers["X-Github-Api-Version"], "Should include API version header")
97
98 // Test https://api.github.com URLs
99 headers = github.GetGitHubHeaders("https://api.github.com/repos/owner/repo")
100 require.Equal(t, "Bearer test_token", headers["Authorization"], "Should include auth header for https://api.github.com")
101 require.Equal(t, "2022-11-28", headers["X-Github-Api-Version"], "Should include API version header")
102 })
103
104 t.Run("NonGitHubURLs", func(t *testing.T) {
105 t.Setenv("DDEV_GITHUB_TOKEN", "test_token")
106
107 // Test non-GitHub URLs
108 testURLs := []string{
109 "https://gitlab.com/owner/repo",
110 "https://bitbucket.org/owner/repo",
111 "https://example.com/file.tar.gz",
112 "https://notgithub.com/owner/repo",
113 }
114
115 for _, testURL := range testURLs {
116 headers := github.GetGitHubHeaders(testURL)
117 require.Empty(t, headers, "Should return empty headers for non-GitHub URL: %s", testURL)
118 }
119 })
120
121 t.Run("NoToken", func(t *testing.T) {
122 t.Setenv("DDEV_GITHUB_TOKEN", "")
123 t.Setenv("GH_TOKEN", "")
124 t.Setenv("GITHUB_TOKEN", "")
125
126 headers := github.GetGitHubHeaders("https://github.com/owner/repo")
127 require.Empty(t, headers, "Should return empty headers when no token is set")
128 })
129}

Callers

nothing calls this directly

Calls 1

GetGitHubHeadersFunction · 0.92

Tested by

no test coverage detected