From fc882832a932e8644998e4ac95140a47349c2df4 Mon Sep 17 00:00:00 2001 From: my-git9 Date: Tue, 21 Feb 2023 01:38:36 +0800 Subject: [PATCH] Use http constants to replace numbers as parameters (#7216) Signed-off-by: xin.li --- config/confighttp/compression_test.go | 6 +++--- config/confighttp/confighttp_test.go | 4 ++-- obsreport/obsreporttest/otelprometheuschecker.go | 2 +- processor/batchprocessor/metrics_test.go | 2 +- service/internal/proctelemetry/process_telemetry_test.go | 2 +- service/telemetry_test.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/confighttp/compression_test.go b/config/confighttp/compression_test.go index e16380a5cd5..12c478e8169 100644 --- a/config/confighttp/compression_test.go +++ b/config/confighttp/compression_test.go @@ -117,7 +117,7 @@ func TestHTTPClientCompression(t *testing.T) { serverURL := fmt.Sprintf("http://%s", ln.Addr().String()) reqBody := bytes.NewBuffer(testBody) - req, err := http.NewRequest("GET", serverURL, reqBody) + req, err := http.NewRequest(http.MethodGet, serverURL, reqBody) require.NoError(t, err, "failed to create request to test handler") client := http.Client{} @@ -216,7 +216,7 @@ func TestHTTPContentDecompressionHandler(t *testing.T) { reqBody, err := tt.reqBodyFunc() require.NoError(t, err, "failed to generate request body: %v", err) - req, err := http.NewRequest("GET", serverURL, reqBody) + req, err := http.NewRequest(http.MethodGet, serverURL, reqBody) require.NoError(t, err, "failed to create request to test handler") req.Header.Set("Content-Encoding", tt.encoding) @@ -245,7 +245,7 @@ func TestHTTPContentCompressionRequestWithNilBody(t *testing.T) { })) defer server.Close() - req, err := http.NewRequest("GET", server.URL, nil) + req, err := http.NewRequest(http.MethodGet, server.URL, nil) require.NoError(t, err, "failed to create request to test handler") client := http.Client{} diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 73b31d3c3d4..21405a5a622 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -764,7 +764,7 @@ func TestHttpCorsWithSettings(t *testing.T) { } func verifyCorsResp(t *testing.T, url string, origin string, maxAge int, extraHeader bool, wantStatus int, wantAllowed bool) { - req, err := http.NewRequest("OPTIONS", url, nil) + req, err := http.NewRequest(http.MethodOptions, url, nil) require.NoError(t, err, "Error creating trace OPTIONS request: %v", err) req.Header.Set("Origin", origin) if extraHeader { @@ -853,7 +853,7 @@ func TestHttpHeaders(t *testing.T) { Headers: tt.headers, } client, _ := setting.ToClient(componenttest.NewNopHost(), componenttest.NewNopTelemetrySettings()) - req, err := http.NewRequest("GET", setting.Endpoint, nil) + req, err := http.NewRequest(http.MethodGet, setting.Endpoint, nil) assert.NoError(t, err) _, err = client.Do(req) assert.NoError(t, err) diff --git a/obsreport/obsreporttest/otelprometheuschecker.go b/obsreport/obsreporttest/otelprometheuschecker.go index 0c3487747aa..2ae8bea9cfc 100644 --- a/obsreport/obsreporttest/otelprometheuschecker.go +++ b/obsreport/obsreporttest/otelprometheuschecker.go @@ -164,7 +164,7 @@ func (pc *prometheusChecker) getMetric(expectedName string, expectedType io_prom } func fetchPrometheusMetrics(handler http.Handler) (map[string]*io_prometheus_client.MetricFamily, error) { - req, err := http.NewRequest("GET", "/metrics", nil) + req, err := http.NewRequest(http.MethodGet, "/metrics", nil) if err != nil { return nil, err } diff --git a/processor/batchprocessor/metrics_test.go b/processor/batchprocessor/metrics_test.go index 49e4c23b33b..389363d66c9 100644 --- a/processor/batchprocessor/metrics_test.go +++ b/processor/batchprocessor/metrics_test.go @@ -139,7 +139,7 @@ func (tt *testTelemetry) assertMetrics(t *testing.T, expected expectedMetrics) { _, _ = view.RetrieveData(v.Name) } - req, err := http.NewRequest("GET", "/metrics", nil) + req, err := http.NewRequest(http.MethodGet, "/metrics", nil) require.NoError(t, err) rr := httptest.NewRecorder() diff --git a/service/internal/proctelemetry/process_telemetry_test.go b/service/internal/proctelemetry/process_telemetry_test.go index c24b933c0d6..5ac3e1b0d90 100644 --- a/service/internal/proctelemetry/process_telemetry_test.go +++ b/service/internal/proctelemetry/process_telemetry_test.go @@ -101,7 +101,7 @@ func setupTelemetry(t *testing.T) testTelemetry { } func fetchPrometheusMetrics(handler http.Handler) (map[string]*io_prometheus_client.MetricFamily, error) { - req, err := http.NewRequest("GET", "/metrics", nil) + req, err := http.NewRequest(http.MethodGet, "/metrics", nil) if err != nil { return nil, err } diff --git a/service/telemetry_test.go b/service/telemetry_test.go index fe1be54666a..573cd36a44e 100644 --- a/service/telemetry_test.go +++ b/service/telemetry_test.go @@ -212,7 +212,7 @@ func createTestMetrics(t *testing.T, mp metric.MeterProvider) *view.View { } func getMetricsFromPrometheus(t *testing.T, handler http.Handler) map[string]*io_prometheus_client.MetricFamily { - req, err := http.NewRequest("GET", "/metrics", nil) + req, err := http.NewRequest(http.MethodGet, "/metrics", nil) require.NoError(t, err) rr := httptest.NewRecorder()