Home / File/ query_test.go — fiber Source File

query_test.go — fiber Source File

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

File go DataBinding PayloadParsers 1 imports 3 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  ec649929_2505_8592_7c6d_a7dfe7415aef["query_test.go"]
  d412afc8_b482_999e_79ca_16b6ad9c2e7c["testing"]
  ec649929_2505_8592_7c6d_a7dfe7415aef --> d412afc8_b482_999e_79ca_16b6ad9c2e7c
  style ec649929_2505_8592_7c6d_a7dfe7415aef 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_QueryBinder_Bind(t *testing.T) {
	t.Parallel()

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

	type Post struct {
		Title string `query:"title"`
	}

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

	req := fasthttp.AcquireRequest()
	req.URI().SetQueryString("name=john&names=john,doe&age=42&posts[0][title]=post1&posts[1][title]=post2&posts[2][title]=post3")

	t.Cleanup(func() {
		fasthttp.ReleaseRequest(req)
	})

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

	require.NoError(t, err)
	require.Equal(t, "john", user.Name)
	require.Equal(t, 42, user.Age)
	require.Len(t, user.Posts, 3)
	require.Equal(t, "post1", user.Posts[0].Title)
	require.Equal(t, "post2", user.Posts[1].Title)
	require.Equal(t, "post3", user.Posts[2].Title)
	require.Contains(t, user.Names, "john")
	require.Contains(t, user.Names, "doe")

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

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

	binder := &QueryBinding{
		EnableSplitting: true,
	}

	type User struct {
// ... (63 more lines)

Domain

Subdomains

Classes

Dependencies

  • testing

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free