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 DataBinding Mappers calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  ff4e3445_1a09_c6b2_adce_360613feb8f0["testFormBindingForType()"]
  149b830f_94cf_4c05_dcdc_ee69b283def3["TestBindingFormForType()"]
  149b830f_94cf_4c05_dcdc_ee69b283def3 -->|calls| ff4e3445_1a09_c6b2_adce_360613feb8f0
  2899e942_a23d_574e_8d47_d28e895c2604["requestWithBody()"]
  ff4e3445_1a09_c6b2_adce_360613feb8f0 -->|calls| 2899e942_a23d_574e_8d47_d28e895c2604
  style ff4e3445_1a09_c6b2_adce_360613feb8f0 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)
	}
}

Domain

Subdomains

Frequently Asked Questions

What does testFormBindingForType() do?
testFormBindingForType() is a function in the gin codebase.
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