Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
asafadar committed Oct 26, 2023
1 parent ad49ebd commit 039bb91
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package history
import (
"context"
"fmt"
"net/http"
"os"
"testing"
"time"

Expand Down Expand Up @@ -51,6 +53,9 @@ func getDefaultPrometheusHistoryProviderConfigForTest() PrometheusHistoryProvide
CtrPodNameLabel: "pod_name",
CtrNameLabel: "name",
CadvisorMetricsJobName: "kubernetes-cadvisor",
Headers: map[string]string{
"Token": "TEST_TOKEN",
},
}
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 039bb91

Please sign in to comment.