Skip to content

Commit

Permalink
Export SetContext to support mocking Transport
Browse files Browse the repository at this point in the history
Fixes github.com/rollbar/issues/104.
  • Loading branch information
bjohnso5 committed Apr 4, 2024
1 parent ed38c7c commit d6a6196
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion async_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (t *AsyncTransport) Close() error {
return nil
}

func (t *AsyncTransport) setContext(ctx context.Context) {
func (t *AsyncTransport) SetContext(ctx context.Context) {
t.ctx = ctx
}

Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewAsync(token, environment, codeVersion, serverHost, serverRoot string, op
if c.ctx == nil {
c.ctx = context.Background()
}
c.Transport.setContext(c.ctx)
c.Transport.SetContext(c.ctx)
return c
}

Expand Down Expand Up @@ -98,10 +98,10 @@ func (c *Client) SetTelemetry(options ...OptionFunc) {
}
func (c *Client) SetContext(ctx context.Context) {
c.ctx = ctx
c.Transport.setContext(ctx)
c.Transport.SetContext(ctx)
}

// SetEnabled sets whether or not Rollbar is enabled.
// SetEnabled sets whether Rollbar is enabled.
// If this is true then this library works as normal.
// If this is false then no calls will be made to the network.
// One place where this is useful is for turning off reporting in tests.
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (t *TestTransport) Close() error {
func (t *TestTransport) Wait() {
t.WaitCalled = true
}
func (t *TestTransport) setContext(ctx context.Context) {
func (t *TestTransport) SetContext(ctx context.Context) {
}

func (t *TestTransport) SetToken(_t string) {}
Expand Down
2 changes: 1 addition & 1 deletion sync_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func (t *SyncTransport) Wait() {}
func (t *SyncTransport) Close() error {
return nil
}
func (t *SyncTransport) setContext(ctx context.Context) {
func (t *SyncTransport) SetContext(ctx context.Context) {
}
6 changes: 3 additions & 3 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type transportOption func(Transport)

func WithTransportContext(ctx context.Context) transportOption {
return func(t Transport) {
t.setContext(ctx)
t.SetContext(ctx)
}
}

Expand Down Expand Up @@ -51,8 +51,8 @@ type Transport interface {
SetHTTPClient(httpClient *http.Client)
// SetItemsPerMinute sets the max number of items to send in a given minute
SetItemsPerMinute(itemsPerMinute int)

setContext(ctx context.Context)
// SetContext sets the context to use for API calls made over the Transport
SetContext(ctx context.Context)
}

// ClientLogger is the interface used by the rollbar Client/Transport to report problems.
Expand Down

0 comments on commit d6a6196

Please sign in to comment.