Skip to content

Commit

Permalink
Added username and password parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharadwajshivam28 committed Oct 23, 2024
1 parent fc42aa0 commit c98c0c4
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"net/http"
"net/http/httptest"
// "reflect"
"strings"
"testing"

Expand Down Expand Up @@ -116,12 +115,14 @@ func Test_GetRoundtripper(t *testing.T) {
},
}
tests := []struct {
name string
provider metricsapi.KeptnMetricsProvider
k8sClient client.Client
want http.RoundTripper
wantErr bool
errorStr string
name string
provider metricsapi.KeptnMetricsProvider
k8sClient client.Client
wantUser string
wantPassword string
wantRoundTripper http.RoundTripper
wantErr bool
errorStr string
}{
{
name: "TestSuccess",
Expand All @@ -140,14 +141,18 @@ func Test_GetRoundtripper(t *testing.T) {
},
},
k8sClient: fake.NewClient(goodsecret),
want: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
},
{
name: "TestSecretNotDefined",
provider: metricsapi.KeptnMetricsProvider{},
k8sClient: fake.NewClient(),
want: promapi.DefaultRoundTripper,
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
},
{
Expand All @@ -167,7 +172,9 @@ func Test_GetRoundtripper(t *testing.T) {
},
},
k8sClient: fake.NewClient(),
want: nil,
wantUser: "myuser",
wantPassword: "mytoken",
wantRoundTripper: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: true,
errorStr: "not found",
},
Expand Down Expand Up @@ -206,9 +213,6 @@ func Test_GetRoundtripper(t *testing.T) {
if !tt.wantErr && got == nil {
t.Errorf("getRoundtripper() returned nil, expected a RoundTripper")
}
// if !reflect.DeepEqual(got, tt.want) {
// t.Errorf("getRoundtripper() got = %v, want %v", got, tt.want)
// }
if tr, ok := got.(*http.Transport); ok {
if tr.TLSClientConfig.InsecureSkipVerify != tt.provider.Spec.InsecureSkipTlsVerify {
t.Errorf("RoundTripper TLSClientConfig.InsecureSkipVerify = %v, expected %v",
Expand Down

0 comments on commit c98c0c4

Please sign in to comment.