github.com/gogf/gf@v1.16.9/net/ghttp/ghttp_unit_mess_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package ghttp_test 8 9 import ( 10 "fmt" 11 "testing" 12 "time" 13 14 "github.com/gogf/gf/frame/g" 15 "github.com/gogf/gf/net/ghttp" 16 "github.com/gogf/gf/test/gtest" 17 ) 18 19 func Test_GetUrl(t *testing.T) { 20 p, _ := ports.PopRand() 21 s := g.Server(p) 22 s.BindHandler("/url", func(r *ghttp.Request) { 23 r.Response.Write(r.GetUrl()) 24 }) 25 s.SetPort(p) 26 s.SetDumpRouterMap(false) 27 s.Start() 28 defer s.Shutdown() 29 30 time.Sleep(100 * time.Millisecond) 31 gtest.C(t, func(t *gtest.T) { 32 prefix := fmt.Sprintf("http://127.0.0.1:%d", p) 33 client := g.Client() 34 client.SetBrowserMode(true) 35 client.SetPrefix(prefix) 36 37 t.Assert(client.GetContent("/url"), prefix+"/url") 38 }) 39 }