Skip to content

Commit

Permalink
[chore]: Use http.MethodGet instead of "GET" (jaegertracing#4248)
Browse files Browse the repository at this point in the history
## Short description of the changes
-  Use http constants to replace numbers

Signed-off-by: xin.li <[email protected]>
  • Loading branch information
my-git9 authored and shubbham1215 committed Feb 22, 2023
1 parent 14f8ebb commit a40db38
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions cmd/all-in-one/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestAllInOne(t *testing.T) {
}

func createTrace(t *testing.T) {
req, err := http.NewRequest("GET", getServicesURL, nil)
req, err := http.NewRequest(http.MethodGet, getServicesURL, nil)
require.NoError(t, err)
req.Header.Add("jaeger-debug-id", "debug")

Expand All @@ -82,7 +82,7 @@ type response struct {
}

func getAPITrace(t *testing.T) {
req, err := http.NewRequest("GET", getTraceURL, nil)
req, err := http.NewRequest(http.MethodGet, getTraceURL, nil)
require.NoError(t, err)

var queryResponse response
Expand All @@ -107,7 +107,7 @@ func getAPITrace(t *testing.T) {
}

func getSamplingStrategy(t *testing.T) {
req, err := http.NewRequest("GET", getSamplingStrategyURL, nil)
req, err := http.NewRequest(http.MethodGet, getSamplingStrategyURL, nil)
require.NoError(t, err)

resp, err := httpClient.Do(req)
Expand Down Expand Up @@ -147,7 +147,7 @@ func faviconCheck(t *testing.T) {
}

func getServicesAPIV3(t *testing.T) {
req, err := http.NewRequest("GET", getServicesAPIV3URL, nil)
req, err := http.NewRequest(http.MethodGet, getServicesAPIV3URL, nil)
require.NoError(t, err)
resp, err := httpClient.Do(req)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/additional_headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAdditionalHeadersHandler(t *testing.T) {
server := httptest.NewServer(handler)
defer server.Close()

req, err := http.NewRequest("GET", server.URL, nil)
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
assert.NoError(t, err)

resp, err := server.Client().Do(req)
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/app/apiv3/grpc_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func testGRPCGatewayWithTenancy(t *testing.T, basePath string, serverTLS tlscfg.
},
}, nil).Once()

req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost%s%s/api/v3/traces/123", strings.Replace(httpLis.Addr().String(), "[::]", "", 1), basePath), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost%s%s/api/v3/traces/123", strings.Replace(httpLis.Addr().String(), "[::]", "", 1), basePath), nil)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
setupRequest(req)
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestTenancyGRPCRejection(t *testing.T) {
},
}, nil).Once()

req, err := http.NewRequest("GET", fmt.Sprintf("http://localhost%s%s/api/v3/traces/123", strings.Replace(httpLis.Addr().String(), "[::]", "", 1), basePath), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost%s%s/api/v3/traces/123", strings.Replace(httpLis.Addr().String(), "[::]", "", 1), basePath), nil)
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
// We don't set tenant header
Expand Down
6 changes: 3 additions & 3 deletions cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ func getJSON(url string, out interface{}) error {
}

func getJSONCustomHeaders(url string, additionalHeaders map[string]string, out interface{}) error {
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
Expand All @@ -834,7 +834,7 @@ func postJSON(url string, req interface{}, out interface{}) error {
if err := encoder.Encode(req); err != nil {
return err
}
r, err := http.NewRequest("POST", url, buf)
r, err := http.NewRequest(http.MethodPost, url, buf)
if err != nil {
return err
}
Expand Down Expand Up @@ -919,7 +919,7 @@ func TestSearchTenancyRejectionHTTP(t *testing.T) {
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
Return(mockTrace, nil).Twice()

req, err := http.NewRequest("GET", ts.server.URL+`/api/traces?traceID=1&traceID=2`, nil)
req, err := http.NewRequest(http.MethodGet, ts.server.URL+`/api/traces?traceID=1&traceID=2`, nil)
assert.NoError(t, err)
req.Header.Add("Accept", "application/json")
// We don't set tenant header
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func TestServerHTTPTLS(t *testing.T) {
readMock := spanReader
readMock.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).Return([]*model.Trace{mockTrace}, nil).Once()
queryString := "/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms"
req, err := http.NewRequest("GET", "https://localhost:"+fmt.Sprintf("%d", ports.QueryHTTP)+queryString, nil)
req, err := http.NewRequest(http.MethodGet, "https://localhost:"+fmt.Sprintf("%d", ports.QueryHTTP)+queryString, nil)
assert.Nil(t, err)
req.Header.Add("Accept", "application/json")

Expand Down Expand Up @@ -769,7 +769,7 @@ func TestServerHTTPTenancy(t *testing.T) {
require.NoError(t, clientError)

queryString := "/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms"
req, err := http.NewRequest("GET", "http://localhost:8080"+queryString, nil)
req, err := http.NewRequest(http.MethodGet, "http://localhost:8080"+queryString, nil)
if test.tenant != "" {
req.Header.Add(tenancyMgr.Header, test.tenant)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/token_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestBearerTokenPropagation(t *testing.T) {

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
require.NoError(t, err)
req.Header.Add(testCase.headerName, testCase.headerValue)

Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/pkg/tracing/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type HTTPClient struct {
// GetJSON executes HTTP GET against specified url and tried to parse
// the response into out object.
func (c *HTTPClient) GetJSON(ctx context.Context, endpoint string, url string, out interface{}) error {
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/bearertoken/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Test_PropagationHandler(t *testing.T) {
r := PropagationHandler(logger, testCase.handler(&stop))
server := httptest.NewServer(r)
defer server.Close()
req, err := http.NewRequest("GET", server.URL, nil)
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
assert.Nil(t, err)
if testCase.sendHeader {
req.Header.Add(testCase.headerName, testCase.headerValue)
Expand Down
2 changes: 1 addition & 1 deletion pkg/recoveryhandler/zap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestNewRecoveryHandler(t *testing.T) {
})

recovery := NewRecoveryHandler(logger, false)(handlerFunc)
req, err := http.NewRequest("GET", "/subdir/asdf", nil)
req, err := http.NewRequest(http.MethodGet, "/subdir/asdf", nil)
assert.NoError(t, err)

res := httptest.NewRecorder()
Expand Down
4 changes: 2 additions & 2 deletions pkg/tenancy/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestProgationHandler(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
handler := &testHttpHandler{}
propH := ExtractTenantHTTPHandler(test.tenancyMgr, handler)
req, err := http.NewRequest("GET", "/", strings.NewReader(""))
req, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
for k, vs := range test.requestHeaders {
for _, v := range vs {
req.Header.Add(k, v)
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestMetadataAnnotator(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
req, err := http.NewRequest("GET", "/", strings.NewReader(""))
req, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
for k, vs := range test.requestHeaders {
for _, v := range vs {
req.Header.Add(k, v)
Expand Down

0 comments on commit a40db38

Please sign in to comment.