From 3ce1d5c1d0f10ab8021b1edfd7253f7ac7861526 Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Tue, 21 Feb 2023 23:15:21 +0800 Subject: [PATCH] chore: use http constants to replace numbers Signed-off-by: xin.li --- cmd/triggerrun/cmd/root_test.go | 2 +- pkg/interceptors/webhook/webhook_test.go | 4 ++-- pkg/sink/sink_test.go | 4 ++-- test/eventlistener_test.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/triggerrun/cmd/root_test.go b/cmd/triggerrun/cmd/root_test.go index 321dc7895..2daf61c24 100644 --- a/cmd/triggerrun/cmd/root_test.go +++ b/cmd/triggerrun/cmd/root_test.go @@ -123,7 +123,7 @@ func Test_processTriggerSpec(t *testing.T) { resources test.Resources } eventBody := json.RawMessage(`{"repository": {"links": {"clone": [{"href": "testurl", "name": "ssh"}, {"href": "testurl", "name": "http"}]}}, "changes": [{"ref": {"displayId": "test-branch"}}]}`) - r, err := http.NewRequest("POST", "URL", bytes.NewReader(eventBody)) + r, err := http.NewRequest(http.MethodPost, "URL", bytes.NewReader(eventBody)) if err != nil { t.Errorf("Cannot create a new request:%s", err) } diff --git a/pkg/interceptors/webhook/webhook_test.go b/pkg/interceptors/webhook/webhook_test.go index d0553fd60..e8d6bdcf3 100644 --- a/pkg/interceptors/webhook/webhook_test.go +++ b/pkg/interceptors/webhook/webhook_test.go @@ -84,7 +84,7 @@ func TestWebHookInterceptor(t *testing.T) { } i := NewInterceptor(webhook, client, "default", nil) - incoming, _ := http.NewRequest("POST", "http://doesnotmatter.example.com", payload) + incoming, _ := http.NewRequest(http.MethodPost, "http://doesnotmatter.example.com", payload) incoming.Header.Add("Content-type", "application/json") resp, err := i.ExecuteTrigger(incoming) if err != nil { @@ -136,7 +136,7 @@ func TestWebHookInterceptor_NotOK(t *testing.T) { } i := NewInterceptor(webhook, client, "default", nil) - incoming, _ := http.NewRequest("POST", "http://doesnotmatter.example.com", payload) + incoming, _ := http.NewRequest(http.MethodPost, "http://doesnotmatter.example.com", payload) resp, err := i.ExecuteTrigger(incoming) if err == nil || resp.StatusCode != http.StatusAccepted { got, _ := httputil.DumpResponse(resp, true) diff --git a/pkg/sink/sink_test.go b/pkg/sink/sink_test.go index 21122a493..8395017a4 100644 --- a/pkg/sink/sink_test.go +++ b/pkg/sink/sink_test.go @@ -1192,7 +1192,7 @@ func TestHandleEvent(t *testing.T) { metricsRecorder := &MetricsHandler{Handler: http.HandlerFunc(sink.HandleEvent)} ts := httptest.NewServer(metricsRecorder.Intercept(sink.NewMetricsRecorderInterceptor())) defer ts.Close() - req, err := http.NewRequest("POST", ts.URL, bytes.NewReader(tc.eventBody)) + req, err := http.NewRequest(http.MethodPost, ts.URL, bytes.NewReader(tc.eventBody)) if err != nil { t.Fatalf("error creating request: %s", err) } @@ -1546,7 +1546,7 @@ func TestExecuteInterceptor_ExtensionChaining(t *testing.T) { }, } - req, err := http.NewRequest("POST", "/", nil) + req, err := http.NewRequest(http.MethodPost, "/", nil) if err != nil { t.Fatalf("http.NewRequest: %v", err) } diff --git a/test/eventlistener_test.go b/test/eventlistener_test.go index f974fadce..da8713e9d 100644 --- a/test/eventlistener_test.go +++ b/test/eventlistener_test.go @@ -484,7 +484,7 @@ func TestEventListenerCreate(t *testing.T) { t.Fatalf("Forwarding stream of data failed:: %v", err) } // Send POST request to EventListener sink - req, err := http.NewRequest("POST", fmt.Sprintf("http://127.0.0.1:%s", portString), bytes.NewBuffer(eventBodyJSON)) + req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:%s", portString), bytes.NewBuffer(eventBodyJSON)) if err != nil { t.Fatalf("Error creating POST request: %s", err) } @@ -558,7 +558,7 @@ func TestEventListenerCreate(t *testing.T) { t.Fatalf("EventListener not ready after trigger auth update: %s", err) } // Send POST request to EventListener sink - req, err = http.NewRequest("POST", fmt.Sprintf("http://127.0.0.1:%s", portString), bytes.NewBuffer(eventBodyJSON)) + req, err = http.NewRequest(http.MethodPost, fmt.Sprintf("http://127.0.0.1:%s", portString), bytes.NewBuffer(eventBodyJSON)) if err != nil { t.Fatalf("Error creating POST request for trigger auth: %s", err) }