Semaphore/api/helpers/helpers_test.go
Denis Gukov 6e1a6d20ca refactor(be): template and environment endpoints use Store
Rename util to helpers
Bind returns bool instead of error
2020-12-04 13:46:02 +05:00

32 lines
539 B
Go

package helpers
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gorilla/mux"
)
func TestGetIntParam(t *testing.T) {
req, _ := http.NewRequest("GET", "/test/123", nil)
rr := httptest.NewRecorder()
r := mux.NewRouter()
r.HandleFunc("/test/{test_id}", mockParam)
r.ServeHTTP(rr, req)
if rr.Code != 200 {
t.Errorf("Response code should be 200 %d", rr.Code)
}
}
func mockParam(w http.ResponseWriter, r *http.Request) {
_, err := GetIntParam("test_id", w, r)
if err != nil {
return
}
w.WriteHeader(200)
}