Skip to content

Commit

Permalink
test(teler): add TestCaddy* cases
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Jun 19, 2024
1 parent b484529 commit d56a949
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,39 @@ func TestHandlerFuncWithNext(t *testing.T) {
// Call the HandlerFuncWithNext function with the mock request, response & next
teler.HandlerFuncWithNext(w, r, next)
}

func TestCaddyHandler(t *testing.T) {
// Create a mock Teler
teler := New()

// Create a mock HTTP request using the httptest package
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()

// Initialize Caddy HTTP handler
handler := teler.CaddyHandler(caddyhttp.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
w.WriteHeader(http.StatusOK)

return nil
}))

// Serve
_ = handler.ServeHTTP(w, r)
}

func TestCaddyHandlerFuncWithNext(t *testing.T) {
// Create a mock Teler
teler := New()

// Create a mock HTTP request using the httptest package
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()

// Initialize Caddy HTTP handler function
next := caddyhttp.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
w.WriteHeader(http.StatusOK)
return nil
})

_ = teler.CaddyHandlerFuncWithNext(w, r, next)
}

0 comments on commit d56a949

Please sign in to comment.