Semaphore/util/util_test.go
2017-02-22 14:17:36 -08:00

33 lines
554 B
Go

package util
import (
"github.com/gin-gonic/gin"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetIntParam(t *testing.T) {
gin.SetMode(gin.TestMode)
r := gin.New()
r.GET("/test/:test_id", mockParam)
req, _ := http.NewRequest("GET", "/test/123", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
if w.Code != 200 {
t.Errorf("Response code should be 200 %d", w.Code)
}
}
func mockParam(w http.ResponseWriter, r *http.Request) {
_, err := GetIntParam("test_id", c)
if err != nil {
return
}
w.WriteHeader(http.StatusOK)
}