From d6a61965f33c308a8a33d963d606c5920d305fde Mon Sep 17 00:00:00 2001 From: Bryan Johnson Date: Thu, 4 Apr 2024 16:49:44 -0400 Subject: [PATCH] Export SetContext to support mocking Transport Fixes github.com/rollbar/rollbar-go/issues/104. --- async_transport.go | 2 +- client.go | 6 +++--- client_test.go | 2 +- sync_transport.go | 2 +- transport.go | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/async_transport.go b/async_transport.go index b935b43..03a84f9 100644 --- a/async_transport.go +++ b/async_transport.go @@ -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 } diff --git a/client.go b/client.go index da6b524..37e9463 100644 --- a/client.go +++ b/client.go @@ -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 } @@ -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. diff --git a/client_test.go b/client_test.go index fb0498d..4027606 100644 --- a/client_test.go +++ b/client_test.go @@ -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) {} diff --git a/sync_transport.go b/sync_transport.go index bcd276b..4f5ab6a 100644 --- a/sync_transport.go +++ b/sync_transport.go @@ -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) { } diff --git a/transport.go b/transport.go index 6c3ba4a..0133cb4 100644 --- a/transport.go +++ b/transport.go @@ -23,7 +23,7 @@ type transportOption func(Transport) func WithTransportContext(ctx context.Context) transportOption { return func(t Transport) { - t.setContext(ctx) + t.SetContext(ctx) } } @@ -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.