From e231839dbdcc41602d78ad749b4f12fb9b73231d Mon Sep 17 00:00:00 2001 From: gjahn <gregor.jahn@bht-berlin.de> Date: Thu, 7 Dec 2023 22:43:21 +0100 Subject: [PATCH] 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 --- routing/routes.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routing/routes.go b/routing/routes.go index a9504cd..f51616b 100644 --- a/routing/routes.go +++ b/routing/routes.go @@ -130,7 +130,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, statePathGroup.Put( "/:name", func( c *f.Ctx ) error { - contentType := c.Get( "Content-Type" ) + contentType := strings.Clone( c.Get( "Content-Type" ) ) _, _, err := mime.ParseMediaType( contentType ) if err != nil { c.Status( http.StatusBadRequest ) @@ -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 ) if err != nil { c.Status( http.StatusInternalServerError ) @@ -175,7 +175,7 @@ func SetRoutes( router *f.App, config *configuration.Config, store state.Store, statePathGroup.Delete( "/:name", func( c *f.Ctx ) error { - name := c.Params( "name" ) + name := strings.Clone( c.Params( "name" ) ) existingItem, err := store.Fetch( name ) if err != nil { return c.SendStatus( http.StatusInternalServerError ) -- GitLab