MCPcopy
hub / github.com/gofiber/fiber / Test_Bind_RespHeader

Function Test_Bind_RespHeader

bind_test.go:941–1015  ·  view source on GitHub ↗

go test -run Test_Bind_Resp_Header -v

(t *testing.T)

Source from the content-addressed store, hash-verified

939
940// go test -run Test_Bind_Resp_Header -v
941func Test_Bind_RespHeader(t *testing.T) {
942 t.Parallel()
943 app := New(Config{
944 EnableSplittingOnParsers: true,
945 })
946 c := app.AcquireCtx(&fasthttp.RequestCtx{})
947
948 type Header struct {
949 Name string
950 Hobby []string
951 ID int
952 }
953 c.Request().SetBody([]byte(``))
954 c.Request().Header.SetContentType("")
955
956 c.Response().Header.Add("id", "1")
957 c.Response().Header.Add("Name", "John Doe")
958 c.Response().Header.Add("Hobby", "golang,fiber")
959 q := new(Header)
960 require.NoError(t, c.Bind().RespHeader(q))
961 require.Len(t, q.Hobby, 2)
962
963 c.Response().Header.Del("hobby")
964 c.Response().Header.Add("Hobby", "golang,fiber,go")
965 q = new(Header)
966 require.NoError(t, c.Bind().RespHeader(q))
967 require.Len(t, q.Hobby, 3)
968
969 empty := new(Header)
970 c.Response().Header.Del("hobby")
971 require.NoError(t, c.Bind().Query(empty))
972 require.Empty(t, empty.Hobby)
973
974 type Header2 struct {
975 Name string
976 Hobby string
977 FavouriteDrinks []string
978 Empty []string
979 Alloc []string
980 No []int64
981 ID int
982 Bool bool
983 }
984
985 c.Response().Header.Add("id", "2")
986 c.Response().Header.Add("Name", "Jane Doe")
987 c.Response().Header.Del("hobby")
988 c.Response().Header.Add("Hobby", "go,fiber")
989 c.Response().Header.Add("favouriteDrinks", "milo,coke,pepsi")
990 c.Response().Header.Add("alloc", "")
991 c.Response().Header.Add("no", "1")
992
993 h2 := new(Header2)
994 h2.Bool = true
995 h2.Name = helloWorld
996 require.NoError(t, c.Bind().RespHeader(h2))
997 require.Equal(t, "go,fiber", h2.Hobby)
998 require.True(t, h2.Bool)

Callers

nothing calls this directly

Calls 11

AcquireCtxMethod · 0.80
RespHeaderMethod · 0.80
NewFunction · 0.70
RequestMethod · 0.65
AddMethod · 0.65
ResponseMethod · 0.65
BindMethod · 0.65
LenMethod · 0.65
DelMethod · 0.65
QueryMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected