Skip to content

Commit

Permalink
adding tests in the common_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Bharadwajshivam28 committed Oct 16, 2024
1 parent 9f8605a commit 06a7d81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"crypto/tls"
"errors"
"net/http"

metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1"
promapi "github.com/prometheus/client_golang/api"
"github.com/prometheus/common/config"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"net/http"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,49 @@ func Test_GetRoundtripper(t *testing.T) {
provider: metricsapi.KeptnMetricsProvider{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: metricsapi.KeptnMetricsProviderSpec{
TargetServer: "someTargetServer",
Type: "",
TargetServer: "",
SecretKeyRef: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "test",
},
Key: "",
Optional: nil,
},
InsecureSkipTlsVerify: false,
},
},
k8sClient: fake.NewClient(goodsecret),
want: config.NewBasicAuthRoundTripper("myuser", "mytoken", "", "", promapi.DefaultRoundTripper),
wantErr: false,
},
{
name: "TestSecretNotDefined",
provider: metricsapi.KeptnMetricsProvider{},
k8sClient: fake.NewClient(),
want: promapi.DefaultRoundTripper,
wantErr: false,
},
{
name: "TestErrorFromGetPrometheusSecretNotExists",
provider: metricsapi.KeptnMetricsProvider{
ObjectMeta: metav1.ObjectMeta{Namespace: "default"},
Spec: metricsapi.KeptnMetricsProviderSpec{
Type: "",
TargetServer: "",
SecretKeyRef: v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: "test",
},
Key: "",
Optional: nil,
},
},
},
k8sClient: fake.NewClient(),
want: nil,
wantErr: true,
errorStr: "not found",
},
{
name: "TestInsecureSkipTlsVerifyEnabled",
provider: metricsapi.KeptnMetricsProvider{
Expand Down

0 comments on commit 06a7d81

Please sign in to comment.