Home / File/ uri_test.go — fiber Source File

uri_test.go — fiber Source File

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

File go DataBinding PayloadParsers 1 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

package binder

import (
	"testing"

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

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

	b := &URIBinding{}
	require.Equal(t, "uri", b.Name())

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

	paramsKey := []string{"name", "age", "posts"}
	paramsVals := []string{"john", "42", "post1,post2,post3"}
	paramsFunc := func(key string, _ ...string) string {
		for i, k := range paramsKey {
			if k == key {
				return paramsVals[i]
			}
		}

		return ""
	}

	err := b.Bind(paramsKey, paramsFunc, &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()
}

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

	binder := &URIBinding{}

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

	paramsKey := []string{"name", "age", "posts"}
	paramsVals := []string{"john", "42", "post1,post2,post3"}
	paramsFunc := func(key string, _ ...string) string {
		for i, k := range paramsKey {
			if k == key {
				return paramsVals[i]
			}
		}

		return ""
	}

	var err error
	for b.Loop() {
		err = binder.Bind(paramsKey, paramsFunc, &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)
}

Domain

Subdomains

Classes

Types

Dependencies

  • testing

Frequently Asked Questions

What does uri_test.go do?
uri_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 uri_test.go?
uri_test.go defines 2 function(s): Benchmark_URIBinding_Bind, Test_URIBinding_Bind.
What does uri_test.go depend on?
uri_test.go imports 1 module(s): testing.
Where is uri_test.go in the architecture?
uri_test.go is located at binder/uri_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