-
Notifications
You must be signed in to change notification settings - Fork 90
/
ctx_test.go
41 lines (33 loc) · 949 Bytes
/
ctx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package clickhouse
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_CtxAddTransportCallback(t *testing.T) {
var flag bool
ctx := context.Background()
ctx = CtxAddTransportCallback(ctx, func(_ *http.Request, _ *http.Response) error {
flag = true
return nil
})
assert.NoError(t, callCtxTransportCallback(ctx,
httptest.NewRequest(http.MethodGet, "http://localhost", nil), httptest.NewRecorder().Result(),
))
assert.True(t, flag)
}
func Test_CtxAddTransportCallback_err(t *testing.T) {
var flag bool
ctx := context.Background()
ctx = CtxAddTransportCallback(ctx, func(_ *http.Request, _ *http.Response) error {
flag = true
return errors.New("some error")
})
assert.EqualError(t, callCtxTransportCallback(ctx,
httptest.NewRequest(http.MethodGet, "http://localhost", nil), httptest.NewRecorder().Result(),
), "some error")
assert.True(t, flag)
}