1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2024-12-04 10:34:44 +02:00
gorocket/helper.go
2024-02-03 21:54:40 +02:00

27 lines
495 B
Go

package gorocket
import (
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
type HandlerHelper struct {
Code int
ResponseBody string
}
func getHandler(t *testing.T, param *HandlerHelper) http.HandlerFunc {
httpStatus := param.Code
if httpStatus == 0 {
httpStatus = http.StatusOK
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(httpStatus)
_, err := w.Write([]byte(param.ResponseBody))
require.NoError(t, err)
})
}