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,42 @@
package httphandlers_test
import (
"io"
"net/http"
"testing"
"fiskerinc.com/modules/common"
"fiskerinc.com/modules/httphandlers"
"fiskerinc.com/modules/testhelper"
)
func TestLogRequest(t *testing.T) {
tests := []testhelper.BasicHttpTest{
{
Name: "GET request",
Request: testhelper.MakeTestRequest(http.MethodGet, "/test", nil),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `null`,
},
{
Name: "POST request",
Request: testhelper.MakeTestRequest(http.MethodPost, "/test", common.Car{VIN: "TESTVIN"}),
ExpectedStatus: http.StatusOK,
ExpectedResponse: `{"vin":"TESTVIN"}`,
},
}
echo := func(w http.ResponseWriter, r *http.Request) {
b, err := io.ReadAll(r.Body)
if err != nil {
w.Write([]byte(err.Error()))
} else {
w.Write(b)
}
}
handler := httphandlers.LogRequest(echo)
for _, test := range tests {
testhelper.RunBasicHttpTest(t, test, handler)
}
}