@@ -142,3 +142,56 @@ func TestConfig(t *testing.T) {
142142 })
143143 }
144144}
145+
146+ func TestGetClient (t * testing.T ) {
147+ tests := []struct {
148+ name string
149+ envVars map [string ]string
150+ expectedHost string
151+ expectedPath string
152+ expectedErr error
153+ }{
154+ {
155+ name : "default config" ,
156+ expectedHost : "api.github.com" ,
157+ expectedPath : "/" ,
158+ expectedErr : nil ,
159+ },
160+ {
161+ name : "non-default config" ,
162+ envVars : map [string ]string {
163+ "METRICS_PATH" : "/otherendpoint" ,
164+ "LISTEN_PORT" : "1111" ,
165+ "LOG_LEVEL" : "DEBUG" ,
166+ "API_URL" : "https://example.com" ,
167+ "REPOS" : "repo1, repo2" ,
168+ "ORGS" : "org1,org2 " ,
169+ "USERS" : " user1, user2 " ,
170+ "GITHUB_RESULTS_PER_PAGE" : "50" ,
171+ "GITHUB_TOKEN" : "token" ,
172+ "GITHUB_RATE_LIMIT_ENABLED" : "false" ,
173+ "FETCH_REPO_RELEASES_ENABLED" : "false" ,
174+ "FETCH_ORGS_CONCURRENCY" : "2" ,
175+ "FETCH_ORG_REPOS_CONCURRENCY" : "3" ,
176+ "FETCH_REPOS_CONCURRENCY" : "4" ,
177+ "FETCH_USERS_CONCURRENCY" : "5" ,
178+ },
179+ expectedHost : "example.com" ,
180+ expectedPath : "/api/v3/" ,
181+ expectedErr : nil ,
182+ },
183+ }
184+ for _ , tt := range tests {
185+ t .Run (tt .name , func (t * testing.T ) {
186+ for k , v := range tt .envVars {
187+ t .Setenv (k , v )
188+ }
189+
190+ cfg , _ := Init ()
191+ client , _ := cfg .GetClient ()
192+
193+ assert .Equal (t , client .BaseURL .Host , tt .expectedHost )
194+ assert .Equal (t , client .BaseURL .Path , tt .expectedPath )
195+ })
196+ }
197+ }
0 commit comments