Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2.0: use default transport to mock http requests #22

Merged
merged 8 commits into from
Mar 25, 2024
14 changes: 9 additions & 5 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func AddToScheme() error {
var DefaultNewClient = NewClient

func NewClient(token, apiEndpoint string) (runtimeclient.Client, error) {
return NewClientWithTransport(token, apiEndpoint, &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
})
}

func NewClientWithTransport(token, apiEndpoint string, transport http.RoundTripper) (runtimeclient.Client, error) {
if err := AddToScheme(); err != nil {
return nil, err
}
Expand All @@ -63,11 +71,7 @@ func NewClient(token, apiEndpoint string) (runtimeclient.Client, error) {
return nil, err
}

cfg.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
}
cfg.Transport = transport
cfg.BearerToken = string(token)
cfg.QPS = 40.0
cfg.Burst = 50
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
func TestNewClientOK(t *testing.T) {
// given
t.Cleanup(gock.OffAll)
gock.New("http://example.com").
gock.New("https://some-dummy-example.com").
Get("api").
Persist().
Reply(200).
BodyString("{}")

// when
cl, err := client.NewClient("cool-token", "http://example.com")
cl, err := client.NewClientWithTransport("cool-token", "https://some-dummy-example.com", gock.DefaultTransport)

// then
require.NoError(t, err)
Expand Down
Loading