Home / File/ binding_msgpack_test.go — gin Source File

binding_msgpack_test.go — gin Source File

Architecture documentation for binding_msgpack_test.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go RequestBinding FormBinding 1 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  70da3a8e_4685_db81_c918_785137844e6a["binding_msgpack_test.go"]
  fefe783b_8987_7aed_66c9_b2860bfc32e7["bytes"]
  70da3a8e_4685_db81_c918_785137844e6a --> fefe783b_8987_7aed_66c9_b2860bfc32e7
  style 70da3a8e_4685_db81_c918_785137844e6a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Copyright 2020 Gin Core Team. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

//go:build !nomsgpack

package binding

import (
	"bytes"
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/ugorji/go/codec"
)

func TestBindingMsgPack(t *testing.T) {
	test := FooStruct{
		Foo: "bar",
	}

	h := new(codec.MsgpackHandle)
	assert.NotNil(t, h)
	buf := bytes.NewBuffer([]byte{})
	assert.NotNil(t, buf)
	err := codec.NewEncoder(buf, h).Encode(test)
	require.NoError(t, err)

	data := buf.Bytes()

	testMsgPackBodyBinding(t,
		MsgPack, "msgpack",
		"/", "/",
		string(data), string(data[1:]))
}

func testMsgPackBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {
	assert.Equal(t, name, b.Name())

	obj := FooStruct{}
	req := requestWithBody(http.MethodPost, path, body)
	req.Header.Add("Content-Type", MIMEMSGPACK)
	err := b.Bind(req, &obj)
	require.NoError(t, err)
	assert.Equal(t, "bar", obj.Foo)

	obj = FooStruct{}
	req = requestWithBody(http.MethodPost, badPath, badBody)
	req.Header.Add("Content-Type", MIMEMSGPACK)
	err = MsgPack.Bind(req, &obj)
	require.Error(t, err)
}

func TestBindingDefaultMsgPack(t *testing.T) {
	assert.Equal(t, MsgPack, Default(http.MethodPost, MIMEMSGPACK))
	assert.Equal(t, MsgPack, Default(http.MethodPut, MIMEMSGPACK2))
}

Subdomains

Dependencies

  • bytes

Frequently Asked Questions

What does binding_msgpack_test.go do?
binding_msgpack_test.go is a source file in the gin codebase, written in go. It belongs to the RequestBinding domain, FormBinding subdomain.
What functions are defined in binding_msgpack_test.go?
binding_msgpack_test.go defines 3 function(s): TestBindingDefaultMsgPack, TestBindingMsgPack, testMsgPackBodyBinding.
What does binding_msgpack_test.go depend on?
binding_msgpack_test.go imports 1 module(s): bytes.
Where is binding_msgpack_test.go in the architecture?
binding_msgpack_test.go is located at binding/binding_msgpack_test.go (domain: RequestBinding, subdomain: FormBinding, directory: binding).

Analyze Your Own Codebase

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

Try Supermodel Free