Skip to content
Snippets Groups Projects
Commit e231839d authored by gjahn's avatar gjahn
Browse files

Fix flaky routes state test

Using the Param "name" to create an Item and persist turns out to be
affected bi Fiber's behaviour of "zero allocation", which means values
may be re-used across requests/contexts.

This caused wrong or chunked up Item names in the ephemeral state, which
only surfaced during unit testing.

For more details see https://docs.gofiber.io/#zero-allocation
parent ff16945c
No related branches found
No related tags found
No related merge requests found
...@@ -130,7 +130,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, ...@@ -130,7 +130,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
statePathGroup.Put( "/:name", func( c *f.Ctx ) error { statePathGroup.Put( "/:name", func( c *f.Ctx ) error {
contentType := c.Get( "Content-Type" ) contentType := strings.Clone( c.Get( "Content-Type" ) )
_, _, err := mime.ParseMediaType( contentType ) _, _, err := mime.ParseMediaType( contentType )
if err != nil { if err != nil {
c.Status( http.StatusBadRequest ) c.Status( http.StatusBadRequest )
...@@ -139,7 +139,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, ...@@ -139,7 +139,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
) )
} }
name := c.Params( "name" ) name := strings.Clone( c.Params( "name" ) )
existingItem, err := store.Fetch( name ) existingItem, err := store.Fetch( name )
if err != nil { if err != nil {
c.Status( http.StatusInternalServerError ) c.Status( http.StatusInternalServerError )
...@@ -175,7 +175,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, ...@@ -175,7 +175,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store,
statePathGroup.Delete( "/:name", func( c *f.Ctx ) error { statePathGroup.Delete( "/:name", func( c *f.Ctx ) error {
name := c.Params( "name" ) name := strings.Clone( c.Params( "name" ) )
existingItem, err := store.Fetch( name ) existingItem, err := store.Fetch( name )
if err != nil { if err != nil {
return c.SendStatus( http.StatusInternalServerError ) return c.SendStatus( http.StatusInternalServerError )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment