Skip to content

Commit dbf974f

Browse files
authored
Merge pull request #113 from rollbar/pawel/make_setContext_public
Export SetContext to support mocking Transport
2 parents ed38c7c + 42501c5 commit dbf974f

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

async_transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (t *AsyncTransport) Close() error {
168168
return nil
169169
}
170170

171-
func (t *AsyncTransport) setContext(ctx context.Context) {
171+
func (t *AsyncTransport) SetContext(ctx context.Context) {
172172
t.ctx = ctx
173173
}
174174

client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewAsync(token, environment, codeVersion, serverHost, serverRoot string, op
6363
if c.ctx == nil {
6464
c.ctx = context.Background()
6565
}
66-
c.Transport.setContext(c.ctx)
66+
c.Transport.SetContext(c.ctx)
6767
return c
6868
}
6969

@@ -98,7 +98,7 @@ func (c *Client) SetTelemetry(options ...OptionFunc) {
9898
}
9999
func (c *Client) SetContext(ctx context.Context) {
100100
c.ctx = ctx
101-
c.Transport.setContext(ctx)
101+
c.Transport.SetContext(ctx)
102102
}
103103

104104
// SetEnabled sets whether or not Rollbar is enabled.
@@ -216,10 +216,12 @@ func (c *Client) SetScrubFields(fields *regexp.Regexp) {
216216
// SetTransform sets the transform function called after the entire payload has been built before it
217217
// is sent to the API.
218218
// The structure of the final payload sent to the API is:
219-
// {
220-
// "access_token": "YOUR_ACCESS_TOKEN",
221-
// "data": { ... }
222-
// }
219+
//
220+
// {
221+
// "access_token": "YOUR_ACCESS_TOKEN",
222+
// "data": { ... }
223+
// }
224+
//
223225
// This function takes a map[string]interface{} which is the value of the data key in the payload
224226
// described above. You can modify this object in-place to make any arbitrary changes you wish to
225227
// make before it is finally sent. Be careful with the modifications you make as they could lead to

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (t *TestTransport) Close() error {
2323
func (t *TestTransport) Wait() {
2424
t.WaitCalled = true
2525
}
26-
func (t *TestTransport) setContext(ctx context.Context) {
26+
func (t *TestTransport) SetContext(ctx context.Context) {
2727
}
2828

2929
func (t *TestTransport) SetToken(_t string) {}

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/rollbar/rollbar-go
22

33
go 1.13
44

5-
require github.com/stretchr/testify v1.7.0
5+
require (
6+
github.com/rollbar/rollbar-go/errors v1.0.0 // indirect
7+
github.com/stretchr/testify v1.7.0
8+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
4+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
35
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
46
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/rollbar/rollbar-go/errors v1.0.0 h1:8wgJym3dOpKeP85ZhQm2WfBwcAfUyXyYVYz2odY04G0=
8+
github.com/rollbar/rollbar-go/errors v1.0.0/go.mod h1:Ie0xEc1Cyj+T4XMO8s0Vf7pMfvSAAy1sb4AYc8aJsao=
59
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
610
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
711
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=

sync_transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ func (t *SyncTransport) Wait() {}
6565
func (t *SyncTransport) Close() error {
6666
return nil
6767
}
68-
func (t *SyncTransport) setContext(ctx context.Context) {
68+
func (t *SyncTransport) SetContext(ctx context.Context) {
6969
}

transport.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type transportOption func(Transport)
2323

2424
func WithTransportContext(ctx context.Context) transportOption {
2525
return func(t Transport) {
26-
t.setContext(ctx)
26+
t.SetContext(ctx)
2727
}
2828
}
2929

@@ -51,8 +51,8 @@ type Transport interface {
5151
SetHTTPClient(httpClient *http.Client)
5252
// SetItemsPerMinute sets the max number of items to send in a given minute
5353
SetItemsPerMinute(itemsPerMinute int)
54-
55-
setContext(ctx context.Context)
54+
// SetContext sets the context to use for API calls made over the Transport
55+
SetContext(ctx context.Context)
5656
}
5757

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

0 commit comments

Comments
 (0)