Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package httphandlers
import (
"net/http"
"net/http/httptest"
"testing"
"fiskerinc.com/modules/testhelper"
)
func TestCheckMethod(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
testCheckMethod(t, CheckMethod(http.MethodGet, handler), http.StatusOK)
testCheckMethod(t, CheckMethod(MethodAll, handler), http.StatusOK)
testCheckMethod(t, CheckMethod(http.MethodPost, handler), http.StatusBadRequest)
}
func testCheckMethod(t *testing.T, fn http.HandlerFunc, expectedStatusCode int) {
req := setupAuthorizeRequest()
recorder := httptest.NewRecorder()
fn(recorder, req)
if recorder.Code != expectedStatusCode {
t.Errorf(testhelper.TestErrorTemplate, "Status code", expectedStatusCode, recorder.Code)
}
}
func setupAuthorizeRequest() *http.Request {
req, _ := http.NewRequest("GET", "http://example.com", nil)
return req
}