Skip to content

Commit 9ad687d

Browse files
authored
fix: Preserve Marketplace.Stubbed during client copy (#4144)
1 parent c13f52c commit 9ad687d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

github/github.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ func (c *Client) initialize() {
467467
c.Issues = (*IssuesService)(&c.common)
468468
c.Licenses = (*LicensesService)(&c.common)
469469
c.Markdown = (*MarkdownService)(&c.common)
470-
c.Marketplace = &MarketplaceService{client: c}
470+
var marketplaceStubbed bool
471+
if c.Marketplace != nil {
472+
marketplaceStubbed = c.Marketplace.Stubbed
473+
}
474+
c.Marketplace = &MarketplaceService{client: c, Stubbed: marketplaceStubbed}
471475
c.Meta = (*MetaService)(&c.common)
472476
c.Migrations = (*MigrationService)(&c.common)
473477
c.Organizations = (*OrganizationsService)(&c.common)
@@ -498,6 +502,9 @@ func (c *Client) copy() *Client {
498502
RateLimitRedirectionalEndpoints: c.RateLimitRedirectionalEndpoints,
499503
secondaryRateLimitReset: c.secondaryRateLimitReset,
500504
}
505+
if c.Marketplace != nil {
506+
clone.Marketplace = &MarketplaceService{Stubbed: c.Marketplace.Stubbed}
507+
}
501508
c.clientMu.Unlock()
502509
if c.client != nil {
503510
clone.client.Transport = c.client.Transport

github/github_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,19 @@ func TestWithAuthToken(t *testing.T) {
508508
t.Error("The header 'Authorization' must not be set")
509509
}
510510
})
511+
512+
t.Run("preserves Marketplace Stubbed field", func(t *testing.T) {
513+
t.Parallel()
514+
515+
c := NewClient(nil)
516+
c.Marketplace.Stubbed = true
517+
518+
c2 := c.WithAuthToken("token")
519+
520+
if !c2.Marketplace.Stubbed {
521+
t.Fatal("WithAuthToken reset Marketplace.Stubbed; want true")
522+
}
523+
})
511524
}
512525

513526
func TestWithEnterpriseURLs(t *testing.T) {

0 commit comments

Comments
 (0)