Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
42
pkg/httphandlers/log_request_test.go
Normal file
42
pkg/httphandlers/log_request_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user