1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00

chore: fix testutils linter warnings (#502)

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-02-19 12:02:06 -08:00
committed by GitHub
parent e4ca20e471
commit 25c6f58535

View File

@@ -2,12 +2,14 @@ package rest
import ( import (
"bytes" "bytes"
"context"
"log" "log"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
"time"
"github.com/inbucket/inbucket/v3/pkg/config" "github.com/inbucket/inbucket/v3/pkg/config"
"github.com/inbucket/inbucket/v3/pkg/message" "github.com/inbucket/inbucket/v3/pkg/message"
@@ -16,24 +18,36 @@ import (
) )
func testRestGet(url string) (*httptest.ResponseRecorder, error) { func testRestGet(url string) (*httptest.ResponseRecorder, error) {
req, err := http.NewRequest("GET", url, nil) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Pass request to handlers directly.
w := httptest.NewRecorder() w := httptest.NewRecorder()
web.Router.ServeHTTP(w, req) web.Router.ServeHTTP(w, req)
return w, nil return w, nil
} }
func testRestPatch(url string, body string) (*httptest.ResponseRecorder, error) { func testRestPatch(url string, body string) (*httptest.ResponseRecorder, error) {
req, err := http.NewRequest("PATCH", url, strings.NewReader(body)) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodPatch, url, strings.NewReader(body))
req.Header.Add("Accept", "application/json") req.Header.Add("Accept", "application/json")
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Pass request to handlers directly.
w := httptest.NewRecorder() w := httptest.NewRecorder()
web.Router.ServeHTTP(w, req) web.Router.ServeHTTP(w, req)
return w, nil return w, nil
} }