@@ -373,17 +373,69 @@ func TestRepositoryFeatures(t *testing.T) {
373373}
374374
375375func TestProjectV1Support (t * testing.T ) {
376- t .Parallel ()
376+ tests := []struct {
377+ name string
378+ hostname string
379+ httpStubs func (* httpmock.Registry )
380+ wantFeatures gh.ProjectsV1Support
381+ }{
382+ {
383+ name : "github.com" ,
384+ hostname : "github.com" ,
385+ wantFeatures : gh .ProjectsV1Unsupported ,
386+ },
387+ {
388+ name : "ghec data residency (ghe.com)" ,
389+ hostname : "stampname.ghe.com" ,
390+ wantFeatures : gh .ProjectsV1Unsupported ,
391+ },
392+ {
393+ name : "GHE 3.16.0" ,
394+ hostname : "git.my.org" ,
395+ httpStubs : func (reg * httpmock.Registry ) {
396+ reg .Register (
397+ httpmock .REST ("GET" , "api/v3/meta" ),
398+ httpmock .StringResponse (`{"installed_version":"3.16.0"}` ),
399+ )
400+ },
401+ wantFeatures : gh .ProjectsV1Supported ,
402+ },
403+ {
404+ name : "GHE 3.16.1" ,
405+ hostname : "git.my.org" ,
406+ httpStubs : func (reg * httpmock.Registry ) {
407+ reg .Register (
408+ httpmock .REST ("GET" , "api/v3/meta" ),
409+ httpmock .StringResponse (`{"installed_version":"3.16.1"}` ),
410+ )
411+ },
412+ wantFeatures : gh .ProjectsV1Supported ,
413+ },
414+ {
415+ name : "GHE 3.17" ,
416+ hostname : "git.my.org" ,
417+ httpStubs : func (reg * httpmock.Registry ) {
418+ reg .Register (
419+ httpmock .REST ("GET" , "api/v3/meta" ),
420+ httpmock .StringResponse (`{"installed_version":"3.17.0"}` ),
421+ )
422+ },
423+ wantFeatures : gh .ProjectsV1Unsupported ,
424+ },
425+ }
377426
378- t .Run ("when the host is enterprise, project v1 is supported" , func (t * testing.T ) {
379- detector := detector {host : "my.ghes.com" }
380- isProjectV1Supported := detector .ProjectsV1 ()
381- require .Equal (t , gh .ProjectsV1Supported , isProjectV1Supported )
382- })
427+ for _ , tt := range tests {
428+ t .Run (tt .name , func (t * testing.T ) {
429+ t .Parallel ()
430+ reg := & httpmock.Registry {}
431+ if tt .httpStubs != nil {
432+ tt .httpStubs (reg )
433+ }
434+ httpClient := & http.Client {}
435+ httpmock .ReplaceTripper (httpClient , reg )
383436
384- t .Run ("when the host is not enterprise, project v1 is not supported" , func (t * testing.T ) {
385- detector := detector {host : "github.com" }
386- isProjectV1Supported := detector .ProjectsV1 ()
387- require .Equal (t , gh .ProjectsV1Unsupported , isProjectV1Supported )
388- })
437+ detector := NewDetector (httpClient , tt .hostname )
438+ require .Equal (t , tt .wantFeatures , detector .ProjectsV1 ())
439+ })
440+ }
389441}
0 commit comments