Skip to content

Commit

Permalink
feat: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj319 committed Dec 30, 2023
1 parent 0c4999d commit 8f5a443
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nirajan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ func TestSimpleRouter(t *testing.T) {
w.WriteHeader(http.StatusOK)
}, GET)

type Params struct {
Name string
Age int
}
router.AddRoute("/:Name/:Age", func(w http.ResponseWriter, r *http.Request, params Params) {
w.WriteHeader(http.StatusCreated)
}, GET)

router.AddRoute("/users/:Id", func(w http.ResponseWriter, r *http.Request, params struct{ Id string }) {
if params.Id != "1" {
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -56,4 +64,16 @@ func TestSimpleRouter(t *testing.T) {
if status := rr.Code; status != http.StatusBadRequest {
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusBadRequest)
}

req, err = http.NewRequest("GET", "/users/geda", nil)
if err != nil {
t.Fatal(err)
}

rr = httptest.NewRecorder()
router.ServeHTTP(rr, req)

if status := rr.Code; status != http.StatusBadRequest {
t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusBadRequest)
}
}

0 comments on commit 8f5a443

Please sign in to comment.