@@ -929,6 +929,67 @@ func handler(code string) {
929929 assert .Equal (t , expected , content )
930930}
931931
932+ func Test_MigrateClientUsage_AcquireAgentOnlyParse (t * testing.T ) {
933+ t .Parallel ()
934+
935+ dir , err := os .MkdirTemp ("" , "mclientparseonly" )
936+ require .NoError (t , err )
937+ defer func () { require .NoError (t , os .RemoveAll (dir )) }()
938+
939+ file := writeTempFile (t , dir , `package main
940+
941+ import (
942+ "fmt"
943+
944+ "github.com/gofiber/fiber/v3"
945+ "github.com/gofiber/fiber/v3/log"
946+ )
947+
948+ var (
949+ ClientID = "id"
950+ ClientSecret = "secret"
951+ )
952+
953+ func handler(code string) {
954+ a := fiber.AcquireAgent()
955+ req := a.Request()
956+ req.Header.SetMethod(fiber.MethodPost)
957+ req.Header.Set("accept", "application/json")
958+ req.SetRequestURI(fmt.Sprintf("https://github.com/login/oauth/access_token?client_id=%s&client_secret=%s&code=%s", ClientID, ClientSecret, code))
959+ if err := a.Parse(); err != nil {
960+ log.Errorf("could not create HTTP request: %v", err)
961+ }
962+ }` )
963+
964+ var buf bytes.Buffer
965+ cmd := newCmd (& buf )
966+ require .NoError (t , v3 .MigrateClientUsage (cmd , dir , nil , nil ))
967+
968+ content := gofmtSource (t , readFile (t , file ))
969+ expected := gofmtSource (t , `package main
970+
971+ import (
972+ "fmt"
973+
974+ "github.com/gofiber/fiber/v3/client"
975+ "github.com/gofiber/fiber/v3/log"
976+ )
977+
978+ var (
979+ ClientID = "id"
980+ ClientSecret = "secret"
981+ )
982+
983+ func handler(code string) {
984+ _, err := client.Post(fmt.Sprintf("https://github.com/login/oauth/access_token?client_id=%s&client_secret=%s&code=%s", ClientID, ClientSecret, code), client.Config{Header: map[string]string{"accept": "application/json"}})
985+ if err != nil {
986+ log.Errorf("could not create HTTP request: %v", err)
987+ }
988+ }` )
989+
990+ assert .Equal (t , expected , content )
991+ }
992+
932993func Test_MigrateClientUsage_RemovesSingleLineImport (t * testing.T ) {
933994 t .Parallel ()
934995
0 commit comments