Home / File/ resp_header_test.go — fiber Source File

resp_header_test.go — fiber Source File

Architecture documentation for resp_header_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go DataBinding Extractors 1 imports 3 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  ffaa6d07_2478_6275_a2d8_10230f0ee2db["resp_header_test.go"]
  d412afc8_b482_999e_79ca_16b6ad9c2e7c["testing"]
  ffaa6d07_2478_6275_a2d8_10230f0ee2db --> d412afc8_b482_999e_79ca_16b6ad9c2e7c
  style ffaa6d07_2478_6275_a2d8_10230f0ee2db fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package binder

import (
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/valyala/fasthttp"
)

func Test_RespHeaderBinder_Bind(t *testing.T) {
	t.Parallel()

	b := &RespHeaderBinding{
		EnableSplitting: true,
	}
	require.Equal(t, "respHeader", b.Name())

	type User struct {
		Name  string   `respHeader:"name"`
		Posts []string `respHeader:"posts"`
		Age   int      `respHeader:"age"`
	}
	var user User

	resp := fasthttp.AcquireResponse()
	resp.Header.Set("name", "john")
	resp.Header.Set("age", "42")
	resp.Header.Set("posts", "post1,post2,post3")

	t.Cleanup(func() {
		fasthttp.ReleaseResponse(resp)
	})

	err := b.Bind(resp, &user)

	require.NoError(t, err)
	require.Equal(t, "john", user.Name)
	require.Equal(t, 42, user.Age)
	require.Equal(t, []string{"post1", "post2", "post3"}, user.Posts)

	b.Reset()
	require.False(t, b.EnableSplitting)
}

func Benchmark_RespHeaderBinder_Bind(b *testing.B) {
	b.ReportAllocs()

	binder := &RespHeaderBinding{
		EnableSplitting: true,
	}

	type User struct {
		Name  string   `respHeader:"name"`
		Posts []string `respHeader:"posts"`
		Age   int      `respHeader:"age"`
	}
	var user User

	resp := fasthttp.AcquireResponse()
	resp.Header.Set("name", "john")
	resp.Header.Set("age", "42")
	resp.Header.Set("posts", "post1,post2,post3")

	b.Cleanup(func() {
		fasthttp.ReleaseResponse(resp)
	})

	var err error
	for b.Loop() {
		err = binder.Bind(resp, &user)
	}

	require.NoError(b, err)
	require.Equal(b, "john", user.Name)
	require.Equal(b, 42, user.Age)
	require.Equal(b, []string{"post1", "post2", "post3"}, user.Posts)
}

func Test_RespHeaderBinder_Bind_ParseError(t *testing.T) {
	b := &RespHeaderBinding{}
	type User struct {
		Age int `respHeader:"age"`
	}
	var user User
	resp := fasthttp.AcquireResponse()
	resp.Header.Set("age", "invalid")
	t.Cleanup(func() { fasthttp.ReleaseResponse(resp) })
	err := b.Bind(resp, &user)
	require.Error(t, err)
}

Domain

Subdomains

Classes

Dependencies

  • testing

Frequently Asked Questions

What does resp_header_test.go do?
resp_header_test.go is a source file in the fiber codebase, written in go. It belongs to the DataBinding domain, Extractors subdomain.
What functions are defined in resp_header_test.go?
resp_header_test.go defines 3 function(s): Benchmark_RespHeaderBinder_Bind, Test_RespHeaderBinder_Bind, Test_RespHeaderBinder_Bind_ParseError.
What does resp_header_test.go depend on?
resp_header_test.go imports 1 module(s): testing.
Where is resp_header_test.go in the architecture?
resp_header_test.go is located at binder/resp_header_test.go (domain: DataBinding, subdomain: Extractors, directory: binder).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free