generated from keboola/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
31 lines (25 loc) · 886 Bytes
/
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
package client
import (
"os"
"github.com/jarcoal/httpmock"
"github.com/keboola/go-client/pkg/client/trace"
)
var testTransport = DefaultTransport() //nolint:gochecknoglobals
// NewTestClient creates the Client for tests.
//
// If the TEST_HTTP_CLIENT_VERBOSE environment variable is set to "true",
// then all HTTP requests and responses are dumped to stdout.
//
// Output may contain unmasked tokens, do not use it in production!
func NewTestClient() Client {
c := New().WithTransport(testTransport)
if os.Getenv("TEST_HTTP_CLIENT_VERBOSE") == "true" { //nolint:forbidigo
c = c.AndTrace(trace.DumpTracer(os.Stdout))
}
return c
}
// NewMockedClient creates the Client with mocked HTTP transport.
func NewMockedClient() (Client, *httpmock.MockTransport) {
mockTransport := httpmock.NewMockTransport()
return NewTestClient().WithTransport(mockTransport), mockTransport
}