github.com/gogf/gf@v1.16.9/net/ghttp/ghttp_unit_ip_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 // static service testing. 8 9 package ghttp_test 10 11 import ( 12 "fmt" 13 "testing" 14 "time" 15 16 "github.com/gogf/gf/frame/g" 17 "github.com/gogf/gf/net/ghttp" 18 "github.com/gogf/gf/test/gtest" 19 ) 20 21 func TestRequest_GetRemoteIp(t *testing.T) { 22 gtest.C(t, func(t *gtest.T) { 23 p, _ := ports.PopRand() 24 s := g.Server(p) 25 s.BindHandler("/", func(r *ghttp.Request) { 26 r.Response.Write(r.GetRemoteIp()) 27 }) 28 s.SetDumpRouterMap(false) 29 s.SetPort(p) 30 s.Start() 31 defer s.Shutdown() 32 33 time.Sleep(100 * time.Millisecond) 34 35 client := g.Client() 36 client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) 37 38 t.Assert(client.GetContent("/"), "127.0.0.1") 39 }) 40 41 }