@@ -479,23 +479,78 @@ func Test_MigrateConfigListenerFields(t *testing.T) {
479
479
require .NoError (t , err )
480
480
defer func () { require .NoError (t , os .RemoveAll (dir )) }()
481
481
482
- file := writeTempFile (t , dir , `package main
482
+ file1 := filepath .Join (dir , "app.go" )
483
+ require .NoError (t , os .WriteFile (file1 , []byte (`package main
483
484
import "github.com/gofiber/fiber/v2"
484
- func main() {
485
- app := fiber.New(fiber.Config{
485
+ func newApp() *fiber.App {
486
+ return fiber.New(fiber.Config{
486
487
Prefork: true,
487
488
Network: "tcp",
489
+ DisableStartupMessage: true,
490
+ EnablePrintRoutes: true,
488
491
})
489
- _ = app
490
- }` )
492
+ }` ), 0o600 ))
493
+
494
+ file2 := filepath .Join (dir , "main.go" )
495
+ require .NoError (t , os .WriteFile (file2 , []byte (`package main
496
+ func main() {
497
+ app := newApp()
498
+ app.Listen(":3000")
499
+ }` ), 0o600 ))
491
500
492
501
var buf bytes.Buffer
493
502
cmd := newCmd (& buf )
494
503
require .NoError (t , v3 .MigrateConfigListenerFields (cmd , dir , nil , nil ))
495
504
496
- content := readFile (t , file )
505
+ content := readFile (t , file1 )
497
506
assert .Contains (t , content , "EnablePrefork: true" )
498
507
assert .Contains (t , content , "ListenerNetwork: \" tcp\" " )
508
+ assert .NotContains (t , content , "DisableStartupMessage" )
509
+ assert .NotContains (t , content , "EnablePrintRoutes" )
510
+ content2 := readFile (t , file2 )
511
+ assert .Contains (t , content2 , "fiber.ListenConfig{" )
512
+ assert .Contains (t , content2 , "DisableStartupMessage: true" )
513
+ assert .Contains (t , content2 , "EnablePrintRoutes: true" )
514
+ assert .Contains (t , buf .String (), "Migrating listener related config fields" )
515
+ }
516
+
517
+ func Test_MigrateConfigListenerFields_ExistingListenConfig (t * testing.T ) {
518
+ t .Parallel ()
519
+
520
+ dir , err := os .MkdirTemp ("" , "mconf2" )
521
+ require .NoError (t , err )
522
+ defer func () { require .NoError (t , os .RemoveAll (dir )) }()
523
+
524
+ file1 := filepath .Join (dir , "app.go" )
525
+ require .NoError (t , os .WriteFile (file1 , []byte (`package main
526
+ import "github.com/gofiber/fiber/v2"
527
+ func newApp() *fiber.App {
528
+ return fiber.New(fiber.Config{
529
+ DisableStartupMessage: true,
530
+ EnablePrintRoutes: true,
531
+ })
532
+ }` ), 0o600 ))
533
+
534
+ file2 := filepath .Join (dir , "main.go" )
535
+ require .NoError (t , os .WriteFile (file2 , []byte (`package main
536
+ import "github.com/gofiber/fiber/v2"
537
+ func main() {
538
+ app := newApp()
539
+ app.Listen(":3000", fiber.ListenConfig{EnablePrefork: true})
540
+ }` ), 0o600 ))
541
+
542
+ var buf bytes.Buffer
543
+ cmd := newCmd (& buf )
544
+ require .NoError (t , v3 .MigrateConfigListenerFields (cmd , dir , nil , nil ))
545
+
546
+ content1 := readFile (t , file1 )
547
+ assert .NotContains (t , content1 , "DisableStartupMessage" )
548
+ assert .NotContains (t , content1 , "EnablePrintRoutes" )
549
+
550
+ content2 := readFile (t , file2 )
551
+ assert .Contains (t , content2 , "EnablePrefork: true" )
552
+ assert .Contains (t , content2 , "DisableStartupMessage: true" )
553
+ assert .Contains (t , content2 , "EnablePrintRoutes: true" )
499
554
assert .Contains (t , buf .String (), "Migrating listener related config fields" )
500
555
}
501
556
0 commit comments