Skip to content

Commit

Permalink
fix 2.0: use default transport to mock http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek committed Mar 22, 2024
1 parent f92e184 commit af94d14
Show file tree
Hide file tree
Showing 2 changed files with 12 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 NewClientWitTransport(token, apiEndpoint, &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, // nolint: gosec
},
})
}

func NewClientWitTransport(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
5 changes: 3 additions & 2 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client_test
import (
"context"
"fmt"
"net/http"
"testing"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
Expand All @@ -26,14 +27,14 @@ import (
func TestNewClientOK(t *testing.T) {
// given
t.Cleanup(gock.OffAll)
gock.New("http://example.com").
gock.New("https://example.com").
Get("api").
Persist().
Reply(200).
BodyString("{}")

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

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

0 comments on commit af94d14

Please sign in to comment.