File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ func NewClient(accessToken string, repo *Repository) *Client {
5959
6060func newClientWithHTTP (accessToken string , repo * Repository , httpClient * http.Client ) * Client {
6161 client := github .NewClient (httpClient )
62- if repo .BaseURL != "" {
62+ if repo != nil && repo .BaseURL != "" {
6363 baseURL , _ := url .Parse (repo .BaseURL )
6464 // Ensure the endpoint URL has a trailing slash.
6565 if ! strings .HasSuffix (baseURL .Path , "/" ) {
Original file line number Diff line number Diff line change @@ -1118,3 +1118,42 @@ func TestCreateTag(t *testing.T) {
11181118 })
11191119 }
11201120}
1121+
1122+ func TestNewClient (t * testing.T ) {
1123+
1124+ t .Parallel ()
1125+ for _ , test := range []struct {
1126+ name string
1127+ token string
1128+ repo * Repository
1129+ }{
1130+ {
1131+ name : "with credentials" ,
1132+ token : "some-token" ,
1133+ },
1134+ {
1135+ name : "with custom repo" ,
1136+ token : "some-token" ,
1137+ repo : & Repository {
1138+ Owner : "some-owner" ,
1139+ Name : "some-repo" ,
1140+ BaseURL : "https://example.com/" ,
1141+ },
1142+ },
1143+ {
1144+ name : "with repo, without base url" ,
1145+ token : "some-token" ,
1146+ repo : & Repository {
1147+ Owner : "some-owner" ,
1148+ Name : "some-repo" ,
1149+ },
1150+ },
1151+ } {
1152+ t .Run (test .name , func (t * testing.T ) {
1153+ client := NewClient (test .token , nil )
1154+ if client == nil {
1155+ t .Fatalf ("expected to create a new client" )
1156+ }
1157+ })
1158+ }
1159+ }
You can’t perform that action at this time.
0 commit comments