From 039bb91c46362488ffcfe4f253017e7a6a6ef815 Mon Sep 17 00:00:00 2001 From: asaf Date: Fri, 27 Oct 2023 01:33:42 +0300 Subject: [PATCH] Add unit test --- .../input/history/history_provider_test.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/recommender/input/history/history_provider_test.go b/vertical-pod-autoscaler/pkg/recommender/input/history/history_provider_test.go index b66552faee1b..44e5f5498617 100644 --- a/vertical-pod-autoscaler/pkg/recommender/input/history/history_provider_test.go +++ b/vertical-pod-autoscaler/pkg/recommender/input/history/history_provider_test.go @@ -19,6 +19,8 @@ package history import ( "context" "fmt" + "net/http" + "os" "testing" "time" @@ -51,6 +53,9 @@ func getDefaultPrometheusHistoryProviderConfigForTest() PrometheusHistoryProvide CtrPodNameLabel: "pod_name", CtrNameLabel: "name", CadvisorMetricsJobName: "kubernetes-cadvisor", + Headers: map[string]string{ + "Token": "TEST_TOKEN", + }, } } @@ -257,6 +262,25 @@ func TestGetMemorySamples(t *testing.T) { assert.Equal(t, histories, map[model.PodID]*PodHistory{podID: podHistory}) } +func TestAuthHeader(t *testing.T) { + historyProvider, err := NewPrometheusHistoryProvider(getDefaultPrometheusHistoryProviderConfigForTest()) + if err != nil { + t.Fatal(err) + } + authHeaderName := "Token" + testToken := "aaaaaaaaaaaa" + tokenEnvVariableName := "TEST_TOKEN" + os.Setenv(tokenEnvVariableName, testToken) + + req, _ := http.NewRequest("GET", "http://example.com", nil) + + _, err = historyProvider.GetClusterHistory() + + assert.Nil(t, err) + assert.Equal(t, testToken, req.Header.Get(authHeaderName)) + defer os.Unsetenv(tokenEnvVariableName) +} + func TestGetNamespacedMemorySamples(t *testing.T) { mockClient := mockPrometheusAPI{} promConfig := getDefaultPrometheusHistoryProviderConfigForTest()