File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,15 @@ func (c *Context) Param(key string) string {
383383 return c .Params .ByName (key )
384384}
385385
386+ // AddParam adds param to context and
387+ // replaces path param key with given value for e2e testing purposes
388+ // Example Route: "/user/:id"
389+ // AddParam("id", 1)
390+ // Result: "/user/1"
391+ func (c * Context ) AddParam (key , value string ) {
392+ c .Params = append (c .Params , Param {Key : key , Value : value })
393+ }
394+
386395// Query returns the keyed url query value if it exists,
387396// otherwise it returns an empty string `("")`.
388397// It is shortcut for `c.Request.URL.Query().Get(key)`
Original file line number Diff line number Diff line change @@ -2137,3 +2137,14 @@ func TestContextWithFallbackValueFromRequestContext(t *testing.T) {
21372137 })
21382138 }
21392139}
2140+
2141+ func TestContextAddParam (t * testing.T ) {
2142+ c := & Context {}
2143+ id := "id"
2144+ value := "1"
2145+ c .AddParam (id , value )
2146+
2147+ v , ok := c .Params .Get (id )
2148+ assert .Equal (t , ok , true )
2149+ assert .Equal (t , value , v )
2150+ }
You can’t perform that action at this time.
0 commit comments