Home / Function/ testFormBindingForType() — gin Function Reference

testFormBindingForType() — gin Function Reference

Architecture documentation for the testFormBindingForType() function in binding_test.go from the gin codebase.

Function go RequestBinding FormBinding calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  13a7de32_6308_7e83_72dc_bcd2d4a99041["testFormBindingForType()"]
  314c6481_2bd0_e5a7_282c_94e41df6062a["binding_test.go"]
  13a7de32_6308_7e83_72dc_bcd2d4a99041 -->|defined in| 314c6481_2bd0_e5a7_282c_94e41df6062a
  f7c11e14_199e_d77b_35aa_23209200a8d0["TestBindingFormForType()"]
  f7c11e14_199e_d77b_35aa_23209200a8d0 -->|calls| 13a7de32_6308_7e83_72dc_bcd2d4a99041
  aebd0564_565b_ba1b_7f92_4baaca0e7b7e["requestWithBody()"]
  13a7de32_6308_7e83_72dc_bcd2d4a99041 -->|calls| aebd0564_565b_ba1b_7f92_4baaca0e7b7e
  style 13a7de32_6308_7e83_72dc_bcd2d4a99041 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binding/binding_test.go lines 1106–1174

func testFormBindingForType(t *testing.T, method, path, badPath, body, badBody string, typ string) {
	b := Form
	assert.Equal(t, "form", b.Name())

	req := requestWithBody(method, path, body)
	if method == http.MethodPost {
		req.Header.Add("Content-Type", MIMEPOSTForm)
	}
	switch typ {
	case "Slice":
		obj := FooStructForSliceType{}
		err := b.Bind(req, &obj)
		require.NoError(t, err)
		assert.Equal(t, []int{1, 2}, obj.SliceFoo)

		obj = FooStructForSliceType{}
		req = requestWithBody(method, badPath, badBody)
		err = JSON.Bind(req, &obj)
		require.Error(t, err)
	case "Struct":
		obj := FooStructForStructType{}
		err := b.Bind(req, &obj)
		require.NoError(t, err)
		assert.Equal(t,
			struct {
				Idx int "form:\"idx\""
			}{Idx: 123},
			obj.StructFoo)
	case "StructPointer":
		obj := FooStructForStructPointerType{}
		err := b.Bind(req, &obj)
		require.NoError(t, err)
		assert.Equal(t,
			struct {
				Name string "form:\"name\""
			}{Name: "thinkerou"},
			*obj.StructPointerFoo)
	case "Map":
		obj := FooStructForMapType{}
		err := b.Bind(req, &obj)
		require.NoError(t, err)
		assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
	case "SliceMap":
		obj := FooStructForSliceMapType{}
		err := b.Bind(req, &obj)
		require.Error(t, err)
	case "Ptr":
		obj := FooStructForStringPtrType{}
		err := b.Bind(req, &obj)
		require.NoError(t, err)
		assert.Nil(t, obj.PtrFoo)
		assert.Equal(t, "test", *obj.PtrBar)

		obj = FooStructForStringPtrType{}
		obj.PtrBar = new(string)
		err = b.Bind(req, &obj)
		require.NoError(t, err)
		assert.Equal(t, "test", *obj.PtrBar)

		objErr := FooStructForMapPtrType{}
		err = b.Bind(req, &objErr)
		require.Error(t, err)

		obj = FooStructForStringPtrType{}
		req = requestWithBody(method, badPath, badBody)
		err = b.Bind(req, &obj)
		require.Error(t, err)
	}
}

Subdomains

Frequently Asked Questions

What does testFormBindingForType() do?
testFormBindingForType() is a function in the gin codebase, defined in binding/binding_test.go.
Where is testFormBindingForType() defined?
testFormBindingForType() is defined in binding/binding_test.go at line 1106.
What does testFormBindingForType() call?
testFormBindingForType() calls 1 function(s): requestWithBody.
What calls testFormBindingForType()?
testFormBindingForType() is called by 1 function(s): TestBindingFormForType.

Analyze Your Own Codebase

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

Try Supermodel Free