Skip to content

Commit

Permalink
fix 2.0: use default transport to mock http requests (#22)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Francisc Munteanu <[email protected]>
  • Loading branch information
MatousJobanek and mfrancisc authored Mar 25, 2024
1 parent 2b38309 commit a7e9be9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit a7e9be9

Please sign in to comment.