github.com/gogf/gf/v2@v2.7.4/internal/httputil/httputils_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 httputil_test 8 9 import ( 10 "testing" 11 12 "github.com/gogf/gf/v2/frame/g" 13 "github.com/gogf/gf/v2/internal/httputil" 14 "github.com/gogf/gf/v2/test/gtest" 15 "github.com/gogf/gf/v2/text/gstr" 16 ) 17 18 func TestBuildParams(t *testing.T) { 19 gtest.C(t, func(t *gtest.T) { 20 data := g.Map{ 21 "a": "1", 22 "b": "2", 23 } 24 params := httputil.BuildParams(data) 25 t.Assert(gstr.Contains(params, "a=1"), true) 26 t.Assert(gstr.Contains(params, "b=2"), true) 27 }) 28 gtest.C(t, func(t *gtest.T) { 29 data := g.Map{ 30 "a": "1", 31 "b": nil, 32 } 33 params := httputil.BuildParams(data) 34 t.Assert(gstr.Contains(params, "a=1"), true) 35 t.Assert(gstr.Contains(params, "b="), false) 36 t.Assert(gstr.Contains(params, "b"), false) 37 }) 38 }