github.com/msales/pkg/v3@v3.24.0/httpx/middleware/common_test.go (about)

     1  package middleware_test
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  	"net/http/httptest"
     7  	"testing"
     8  
     9  	"github.com/msales/pkg/v3/httpx/middleware"
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestWithCommon(t *testing.T) {
    14  	var called bool
    15  
    16  	h := middleware.WithCommon(context.Background(), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    17  		called = true
    18  	}))
    19  
    20  	req, _ := http.NewRequest("GET", "/", nil)
    21  	resp := httptest.NewRecorder()
    22  
    23  	h.ServeHTTP(resp, req)
    24  
    25  	assert.True(t, called)
    26  }