@@ -259,3 +259,46 @@ data "github_ip_ranges" "test" {}
259259 })
260260 })
261261}
262+
263+ func Test_ghCLIHostFromAPIHost (t * testing.T ) {
264+ testCases := []struct {
265+ name string
266+ host string
267+ expectedHost string
268+ }{
269+ {
270+ name : "dotcom API host is mapped to dotcom host" ,
271+ host : "api.github.com" ,
272+ expectedHost : "github.com" ,
273+ },
274+ {
275+ name : "ghec API host has api. prefix stripped" ,
276+ host : "api.my-enterprise.ghe.com" ,
277+ expectedHost : "my-enterprise.ghe.com" ,
278+ },
279+ {
280+ name : "ghec API host with numbers has api. prefix stripped" ,
281+ host : "api.customer-123.ghe.com" ,
282+ expectedHost : "customer-123.ghe.com" ,
283+ },
284+ {
285+ name : "ghes host is passed through unchanged" ,
286+ host : "github.example.com" ,
287+ expectedHost : "github.example.com" ,
288+ },
289+ {
290+ name : "ghes host with port is passed through unchanged" ,
291+ host : "github.example.com:8443" ,
292+ expectedHost : "github.example.com:8443" ,
293+ },
294+ }
295+
296+ for _ , tc := range testCases {
297+ t .Run (tc .name , func (t * testing.T ) {
298+ got := ghCLIHostFromAPIHost (tc .host )
299+ if got != tc .expectedHost {
300+ t .Errorf ("ghCLIHostFromAPIHost(%q) = %q, want %q" , tc .host , got , tc .expectedHost )
301+ }
302+ })
303+ }
304+ }
0 commit comments