Repository: go-fuego/fuego

Issue:
Allow setting of Request in MockContext
**Is your feature request related to a problem? Please describe.**
One of my controllers accesses `c.Request().RequestURI`, `c` being a `fuego.ContextNoBody`.
In my tests I use `fuego.NewMockContext()`.  `fuego.MockContext` has a private field `request` of type `*http.Request` that can be read with `mockCtx.Request()` but is not set during initialization, thus returning `nil`. 

**Describe the solution you'd like**
I would like `fuego.MockContext.request` to be public / settable.

**Describe alternatives you've considered**
For now I use this hack:
```go
func setMockContextRequest[B, P any](ctx *fuego.MockContext[B, P], req *http.Request) {
	v := reflect.ValueOf(ctx).Elem().FieldByName("request")
	reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem().Set(reflect.ValueOf(req))
}
```


Hints from issue comments:
@slyang08: Hi @Resteklicken,
Can I have a try to take this issue?@Resteklicken: > Hi [@Resteklicken](https://github.com/Resteklicken), Can I have a try to take this issue?

Hey, sorry for the late reply and thank you for the willingness to contribute! 
I would have said go for it, but @dylanhitt seems to already have implemented it.

Solution patch:
diff --git a/mock_context.go b/mock_context.go
index c2788d2..d35d056 100644
--- a/mock_context.go
+++ b/mock_context.go
@@ -107,6 +107,10 @@ func (m *MockContext[B, P]) PathParamInt(name string) int {
 	return 0
 }
 
+func (m *MockContext[B, P]) SetRequest(r *http.Request) {
+	m.request = r
+}
+
 // Request returns the mock request
 func (m *MockContext[B, P]) Request() *http.Request {
 	return m.request



Test patch:
diff --git a/mock_context_test.go b/mock_context_test.go
index fa27576..0f50cd1 100644
--- a/mock_context_test.go
+++ b/mock_context_test.go
@@ -2,6 +2,7 @@ package fuego_test
 
 import (
 	"errors"
+	"net/http"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -195,3 +196,24 @@ func TestMockContextNoBody(t *testing.T) {
 		require.Equal(t, "Hello, ", response)
 	})
 }
+
+func Test_SetRequest(t *testing.T) {
+	t.Run("base", func(t *testing.T) {
+		ctx := fuego.NewMockContextNoBody()
+		req, err := http.NewRequest(http.MethodGet, "/test?foo=bar", nil)
+		require.NoError(t, err)
+
+		ctx.SetRequest(req)
+
+		retrievedReq := ctx.Request()
+		require.NotNil(t, retrievedReq)
+		assert.Equal(t, http.MethodGet, retrievedReq.Method)
+		assert.Equal(t, "/test?foo=bar", retrievedReq.URL.String())
+	})
+
+	t.Run("request should be nil", func(t *testing.T) {
+		ctx := fuego.NewMockContextNoBody()
+		r := ctx.Request()
+		require.Nil(t, r)
+	})
+}