@@ -130,3 +130,128 @@ func TestDefaultAPIURL(t *testing.T) {
130130 t .Errorf ("DefaultAPIURL = %v, want https://api.keyway.sh" , DefaultAPIURL )
131131 }
132132}
133+
134+ func TestGetGitHubURL_Default (t * testing.T ) {
135+ os .Unsetenv ("KEYWAY_GITHUB_URL" )
136+
137+ url := GetGitHubURL ()
138+ if url != DefaultGitHubBaseURL {
139+ t .Errorf ("GetGitHubURL() = %v, want %v" , url , DefaultGitHubBaseURL )
140+ }
141+ }
142+
143+ func TestGetGitHubURL_FromEnv (t * testing.T ) {
144+ os .Setenv ("KEYWAY_GITHUB_URL" , "https://github.example.com" )
145+ defer os .Unsetenv ("KEYWAY_GITHUB_URL" )
146+
147+ url := GetGitHubURL ()
148+ if url != "https://github.example.com" {
149+ t .Errorf ("GetGitHubURL() = %v, want https://github.example.com" , url )
150+ }
151+ }
152+
153+ func TestGetGitHubURL_TrimsTrailingSlash (t * testing.T ) {
154+ os .Setenv ("KEYWAY_GITHUB_URL" , "https://github.example.com/" )
155+ defer os .Unsetenv ("KEYWAY_GITHUB_URL" )
156+
157+ url := GetGitHubURL ()
158+ if url != "https://github.example.com" {
159+ t .Errorf ("GetGitHubURL() = %v, want https://github.example.com" , url )
160+ }
161+ }
162+
163+ func TestGetGitHubAPIURL_Default (t * testing.T ) {
164+ os .Unsetenv ("KEYWAY_GITHUB_API_URL" )
165+ os .Unsetenv ("KEYWAY_GITHUB_URL" )
166+
167+ url := GetGitHubAPIURL ()
168+ if url != DefaultGitHubAPIURL {
169+ t .Errorf ("GetGitHubAPIURL() = %v, want %v" , url , DefaultGitHubAPIURL )
170+ }
171+ }
172+
173+ func TestGetGitHubAPIURL_FromEnv (t * testing.T ) {
174+ os .Setenv ("KEYWAY_GITHUB_API_URL" , "https://api.github.example.com" )
175+ defer os .Unsetenv ("KEYWAY_GITHUB_API_URL" )
176+
177+ url := GetGitHubAPIURL ()
178+ if url != "https://api.github.example.com" {
179+ t .Errorf ("GetGitHubAPIURL() = %v, want https://api.github.example.com" , url )
180+ }
181+ }
182+
183+ func TestGetGitHubAPIURL_DerivedFromGHE (t * testing.T ) {
184+ os .Unsetenv ("KEYWAY_GITHUB_API_URL" )
185+ os .Setenv ("KEYWAY_GITHUB_URL" , "https://github.example.com" )
186+ defer os .Unsetenv ("KEYWAY_GITHUB_URL" )
187+
188+ url := GetGitHubAPIURL ()
189+ if url != "https://github.example.com/api/v3" {
190+ t .Errorf ("GetGitHubAPIURL() = %v, want https://github.example.com/api/v3" , url )
191+ }
192+ }
193+
194+ func TestGetGitHubAPIURL_ExplicitOverridesGHE (t * testing.T ) {
195+ os .Setenv ("KEYWAY_GITHUB_API_URL" , "https://custom-api.example.com" )
196+ os .Setenv ("KEYWAY_GITHUB_URL" , "https://github.example.com" )
197+ defer os .Unsetenv ("KEYWAY_GITHUB_API_URL" )
198+ defer os .Unsetenv ("KEYWAY_GITHUB_URL" )
199+
200+ url := GetGitHubAPIURL ()
201+ if url != "https://custom-api.example.com" {
202+ t .Errorf ("GetGitHubAPIURL() = %v, want https://custom-api.example.com" , url )
203+ }
204+ }
205+
206+ func TestGetGitHubBaseURL_DelegatesToGetGitHubURL (t * testing.T ) {
207+ os .Unsetenv ("KEYWAY_GITHUB_URL" )
208+
209+ if GetGitHubBaseURL () != GetGitHubURL () {
210+ t .Error ("GetGitHubBaseURL() should delegate to GetGitHubURL()" )
211+ }
212+ }
213+
214+ func TestGetDocsURL_Default (t * testing.T ) {
215+ os .Unsetenv ("KEYWAY_DOCS_URL" )
216+
217+ url := GetDocsURL ()
218+ if url != DefaultDocsURL {
219+ t .Errorf ("GetDocsURL() = %v, want %v" , url , DefaultDocsURL )
220+ }
221+ }
222+
223+ func TestGetDocsURL_FromEnv (t * testing.T ) {
224+ os .Setenv ("KEYWAY_DOCS_URL" , "https://docs.example.com" )
225+ defer os .Unsetenv ("KEYWAY_DOCS_URL" )
226+
227+ url := GetDocsURL ()
228+ if url != "https://docs.example.com" {
229+ t .Errorf ("GetDocsURL() = %v, want https://docs.example.com" , url )
230+ }
231+ }
232+
233+ func TestIsCustomAPIURL_NotSet (t * testing.T ) {
234+ os .Unsetenv ("KEYWAY_API_URL" )
235+
236+ if IsCustomAPIURL () {
237+ t .Error ("IsCustomAPIURL() should return false when not set" )
238+ }
239+ }
240+
241+ func TestIsCustomAPIURL_SetToDefault (t * testing.T ) {
242+ os .Setenv ("KEYWAY_API_URL" , DefaultAPIURL )
243+ defer os .Unsetenv ("KEYWAY_API_URL" )
244+
245+ if IsCustomAPIURL () {
246+ t .Error ("IsCustomAPIURL() should return false when set to default" )
247+ }
248+ }
249+
250+ func TestIsCustomAPIURL_SetToCustom (t * testing.T ) {
251+ os .Setenv ("KEYWAY_API_URL" , "https://api.example.com" )
252+ defer os .Unsetenv ("KEYWAY_API_URL" )
253+
254+ if ! IsCustomAPIURL () {
255+ t .Error ("IsCustomAPIURL() should return true when set to custom URL" )
256+ }
257+ }
0 commit comments