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

Function Test_Ctx_Append

ctx_test.go:694–727  ·  view source on GitHub ↗

go test -run Test_Ctx_Append

(t *testing.T)

Source from the content-addressed store, hash-verified

692
693// go test -run Test_Ctx_Append
694func Test_Ctx_Append(t *testing.T) {
695 t.Parallel()
696 app := New()
697 c := app.AcquireCtx(&fasthttp.RequestCtx{})
698
699 c.Append("X-Test", "Hello")
700 c.Append("X-Test", "World")
701 c.Append("X-Test", "Hello", "World")
702 // similar value in the middle
703 c.Append("X2-Test", "World")
704 c.Append("X2-Test", "XHello")
705 c.Append("X2-Test", "Hello", "World")
706 // similar value at the start
707 c.Append("X3-Test", "XHello")
708 c.Append("X3-Test", "World")
709 c.Append("X3-Test", "Hello", "World")
710 // try it with multiple similar values
711 c.Append("X4-Test", "XHello")
712 c.Append("X4-Test", "Hello")
713 c.Append("X4-Test", "HelloZ")
714 c.Append("X4-Test", "YHello")
715 c.Append("X4-Test", "Hello")
716 c.Append("X4-Test", "YHello")
717 c.Append("X4-Test", "HelloZ")
718 c.Append("X4-Test", "XHello")
719 // without append value
720 c.Append("X-Custom-Header")
721
722 require.Equal(t, "Hello, World", string(c.Response().Header.Peek("X-Test")))
723 require.Equal(t, "World, XHello, Hello", string(c.Response().Header.Peek("X2-Test")))
724 require.Equal(t, "XHello, World, Hello", string(c.Response().Header.Peek("X3-Test")))
725 require.Equal(t, "XHello, Hello, HelloZ, YHello", string(c.Response().Header.Peek("X4-Test")))
726 require.Empty(t, string(c.Response().Header.Peek("x-custom-header")))
727}
728
729// go test -v -run=^$ -bench=Benchmark_Ctx_Append -benchmem -count=4
730func Benchmark_Ctx_Append(b *testing.B) {

Callers

nothing calls this directly

Calls 4

AcquireCtxMethod · 0.80
NewFunction · 0.70
AppendMethod · 0.65
ResponseMethod · 0.65

Tested by

no test coverage detected