Skip to content

Commit

Permalink
test: TestRequest utility ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemmahlees committed Apr 24, 2024
1 parent 6b67ed8 commit 91e77f8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utils/testHelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"io"
"net/http"
"reflect"
"strings"
"testing"

"github.com/go-chi/chi/v5"
"github.com/kareemmahlees/meta-x/lib"

"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -125,3 +127,16 @@ func TestSliceOfPointersToSliceOfValues(t *testing.T) {

assert.IsType(t, reflect.SliceOf(reflect.TypeOf("")), reflect.TypeOf(soptsov))
}

func TestRequestTest(t *testing.T) {
r := chi.NewRouter()

r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello"))
})

rr := TestRequest(r, http.MethodGet, "/", http.NoBody)

assert.Equal(t, rr.Code, http.StatusOK)
assert.Equal(t, rr.Body.String(), "Hello")
}

0 comments on commit 91e77f8

Please sign in to comment.