@@ -131,6 +131,37 @@ func handler(c fiber.Ctx) error {
131131 assert .Equal (t , 2 , strings .Count (second , "SetContext(" ))
132132}
133133
134+ func Test_MigrateContextMethods_UserContextOnlyMultipleRuns (t * testing.T ) {
135+ t .Parallel ()
136+
137+ dir , err := os .MkdirTemp ("" , "mcmtestuserctx" )
138+ require .NoError (t , err )
139+ defer func () { require .NoError (t , os .RemoveAll (dir )) }()
140+
141+ file := writeTempFile (t , dir , `package main
142+ import "github.com/gofiber/fiber/v2"
143+ func handler(c fiber.Ctx) error {
144+ ctx := c.UserContext()
145+ _ = ctx
146+ return nil
147+ }` )
148+
149+ var buf bytes.Buffer
150+ cmd := newCmd (& buf )
151+ require .NoError (t , v3 .MigrateContextMethods (cmd , dir , nil , nil ))
152+
153+ first := readFile (t , file )
154+ require .Contains (t , first , "ctx := c.Context()" )
155+ require .NotContains (t , first , ".RequestCtx()" )
156+ require .Contains (t , first , "// fiber:context-methods migrated" )
157+
158+ require .NoError (t , v3 .MigrateContextMethods (cmd , dir , nil , nil ))
159+ second := readFile (t , file )
160+ assert .Equal (t , first , second )
161+ assert .Equal (t , 1 , strings .Count (second , "ctx := c.Context()" ))
162+ assert .Equal (t , 0 , strings .Count (second , ".RequestCtx()" ))
163+ }
164+
134165func Test_MigrateContextMethods_SkipNonFiber (t * testing.T ) {
135166 t .Parallel ()
136167
0 commit comments