Skip to content

Commit

Permalink
Merge pull request #29 from zc2638/fix/ut
Browse files Browse the repository at this point in the history
fix ut to `httptest.NewRequest`
  • Loading branch information
zc2638 authored Nov 8, 2023
2 parents d9f3ba3 + 5eb5081 commit eb4ba57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 2 additions & 4 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestEndpoints_ServeHTTPNotFound(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "http://localhost", nil)
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
w := httptest.NewRecorder()

var es Endpoints
Expand Down Expand Up @@ -71,9 +71,7 @@ func TestEndpoints_ServeHTTP(t *testing.T) {
http.MethodConnect,
}
for _, method := range methods {
req, err := http.NewRequest(strings.ToUpper(method), "http://localhost", nil)
assert.Nil(t, err)

req := httptest.NewRequest(strings.ToUpper(method), "http://localhost", nil)
w := httptest.NewRecorder()
es.ServeHTTP(w, req)
assert.Equal(t, strings.ToUpper(w.Body.String()), strings.ToUpper(method))
Expand Down
3 changes: 2 additions & 1 deletion types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package types
import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -137,7 +138,7 @@ func TestAddURLParamsToContext(t *testing.T) {
}

func TestURLParam(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, "/", nil)
req := httptest.NewRequest(http.MethodGet, "/", nil)
ctx := AddURLParamsToContext(req.Context(), map[string]string{
"name": "zc",
})
Expand Down

0 comments on commit eb4ba57

Please sign in to comment.