diff --git a/github/github.go b/github/github.go index 1e79096856a..9ea62689684 100644 --- a/github/github.go +++ b/github/github.go @@ -467,7 +467,11 @@ func (c *Client) initialize() { c.Issues = (*IssuesService)(&c.common) c.Licenses = (*LicensesService)(&c.common) c.Markdown = (*MarkdownService)(&c.common) - c.Marketplace = &MarketplaceService{client: c} + var marketplaceStubbed bool + if c.Marketplace != nil { + marketplaceStubbed = c.Marketplace.Stubbed + } + c.Marketplace = &MarketplaceService{client: c, Stubbed: marketplaceStubbed} c.Meta = (*MetaService)(&c.common) c.Migrations = (*MigrationService)(&c.common) c.Organizations = (*OrganizationsService)(&c.common) @@ -498,6 +502,9 @@ func (c *Client) copy() *Client { RateLimitRedirectionalEndpoints: c.RateLimitRedirectionalEndpoints, secondaryRateLimitReset: c.secondaryRateLimitReset, } + if c.Marketplace != nil { + clone.Marketplace = &MarketplaceService{Stubbed: c.Marketplace.Stubbed} + } c.clientMu.Unlock() if c.client != nil { clone.client.Transport = c.client.Transport diff --git a/github/github_test.go b/github/github_test.go index e321da98a09..72e88afc7c3 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -508,6 +508,19 @@ func TestWithAuthToken(t *testing.T) { t.Error("The header 'Authorization' must not be set") } }) + + t.Run("preserves Marketplace Stubbed field", func(t *testing.T) { + t.Parallel() + + c := NewClient(nil) + c.Marketplace.Stubbed = true + + c2 := c.WithAuthToken("token") + + if !c2.Marketplace.Stubbed { + t.Fatal("WithAuthToken reset Marketplace.Stubbed; want true") + } + }) } func TestWithEnterpriseURLs(t *testing.T) {