Skip to content

Commit

Permalink
Merge pull request #451 from rhmdnd/add-e2e-test-for-metrics-http-ver…
Browse files Browse the repository at this point in the history
…sion

Add an integration test to verify HTTP version usage
  • Loading branch information
openshift-ci[bot] authored Oct 26, 2023
2 parents 5565a8a + 287f726 commit 6dfae1c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/e2e/framework/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,31 @@ func AssertEachMetric(namespace string, expectedMetrics map[string]int) error {
return nil
}

func (f *Framework) AssertMetricsEndpointUsesHTTPVersion(endpoint, version string) error {
ocPath, err := exec.LookPath("oc")
if err != nil {
return err
}

curlCMD := "curl -i -ks -H \"Authorization: Bearer `cat /var/run/secrets/kubernetes.io/serviceaccount/token`\" " + endpoint
// We're just under test.
// G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM)
// #nosec
cmd := exec.Command(ocPath,
"run", "--rm", "-i", "--restart=Never", "--image=registry.fedoraproject.org/fedora-minimal:latest",
"-n", f.OperatorNamespace, "metrics-test", "--", "bash", "-c", curlCMD,
)

out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error getting output %s", err)
}
if !strings.Contains(string(out), version) {
return fmt.Errorf("metric endpoint is not using %s", version)
}
return nil
}

func assertMetric(content, metric string, expected int) error {
val, err := parseMetric(content, metric)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/parallel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2795,3 +2795,20 @@ func TestScheduledSuiteTimeoutFail(t *testing.T) {
t.Fatal("The scan should have the timeout annotation")
}
}

func TestResultServerHTTPVersion(t *testing.T) {
t.Parallel()
f := framework.Global
endpoints := []string{
fmt.Sprintf("https://metrics.%s.svc:8585/metrics-co", f.OperatorNamespace),
fmt.Sprintf("http://metrics.%s.svc:8383/metrics", f.OperatorNamespace),
}

expectedHTTPVersion := "HTTP/1.1"
for _, endpoint := range endpoints {
err := f.AssertMetricsEndpointUsesHTTPVersion(endpoint, expectedHTTPVersion)
if err != nil {
t.Fatal(err)
}
}
}

0 comments on commit 6dfae1c

Please sign in to comment.