json_test.go — fiber Source File
Architecture documentation for json_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b5c7d338_90e1_2834_abc9_49dc09418b2f["json_test.go"] 51bcd786_d798_f14b_1fed_64e8c2c48d8e["json"] b5c7d338_90e1_2834_abc9_49dc09418b2f --> 51bcd786_d798_f14b_1fed_64e8c2c48d8e style b5c7d338_90e1_2834_abc9_49dc09418b2f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package binder
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func Test_JSON_Binding_Bind(t *testing.T) {
t.Parallel()
b := &JSONBinding{
JSONDecoder: json.Unmarshal,
}
require.Equal(t, "json", b.Name())
type Post struct {
Title string `json:"title"`
}
type User struct {
Name string `json:"name"`
Posts []Post `json:"posts"`
Age int `json:"age"`
}
var user User
err := b.Bind([]byte(`{"name":"john","age":42,"posts":[{"title":"post1"},{"title":"post2"},{"title":"post3"}]}`), &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)
b.Reset()
require.Nil(t, b.JSONDecoder)
}
func Benchmark_JSON_Binding_Bind(b *testing.B) {
b.ReportAllocs()
binder := &JSONBinding{
JSONDecoder: json.Unmarshal,
}
type User struct {
Name string `json:"name"`
Posts []string `json:"posts"`
Age int `json:"age"`
}
var user User
var err error
for b.Loop() {
err = binder.Bind([]byte(`{"name":"john","age":42,"posts":["post1","post2","post3"]}`), &user)
}
require.NoError(b, err)
require.Equal(b, "john", user.Name)
require.Equal(b, 42, user.Age)
require.Len(b, user.Posts, 3)
require.Equal(b, "post1", user.Posts[0])
require.Equal(b, "post2", user.Posts[1])
require.Equal(b, "post3", user.Posts[2])
}
Domain
Subdomains
Dependencies
- json
Source
Frequently Asked Questions
What does json_test.go do?
json_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 json_test.go?
json_test.go defines 2 function(s): Benchmark_JSON_Binding_Bind, Test_JSON_Binding_Bind.
What does json_test.go depend on?
json_test.go imports 1 module(s): json.
Where is json_test.go in the architecture?
json_test.go is located at binder/json_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