Home / Function/ TestFormatBindData() — fiber Function Reference

TestFormatBindData() — fiber Function Reference

Architecture documentation for the TestFormatBindData() function in mapping_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  9bc1002a_6eb1_e4e7_30a8_01c910a07511["TestFormatBindData()"]
  ecb7a598_be7d_ed73_d2c3_8ca5f67838de["mapping_test.go"]
  9bc1002a_6eb1_e4e7_30a8_01c910a07511 -->|defined in| ecb7a598_be7d_ed73_d2c3_8ca5f67838de
  style 9bc1002a_6eb1_e4e7_30a8_01c910a07511 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

binder/mapping_test.go lines 246–311

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

	t.Run("string value with valid key", func(t *testing.T) {
		t.Parallel()

		out := struct{}{}
		data := make(map[string][]string)
		err := formatBindData("query", out, data, "name", "John", false, false)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if len(data["name"]) != 1 || data["name"][0] != "John" {
			t.Fatalf("expected data[\"name\"] = [John], got %v", data["name"])
		}
	})

	t.Run("unsupported value type", func(t *testing.T) {
		t.Parallel()

		out := struct{}{}
		data := make(map[string][]string)
		err := formatBindData("query", out, data, "age", 30, false, false) // int is unsupported
		if err == nil {
			t.Fatal("expected an error, got nil")
		}
	})

	t.Run("bracket notation parsing error", func(t *testing.T) {
		t.Parallel()

		out := struct{}{}
		data := make(map[string][]string)
		err := formatBindData("query", out, data, "invalid[", "value", false, true) // malformed bracket notation
		if err == nil {
			t.Fatal("expected an error, got nil")
		}
	})

	t.Run("handling multipart file headers", func(t *testing.T) {
		t.Parallel()

		out := struct{}{}
		data := make(map[string][]*multipart.FileHeader)
		files := []*multipart.FileHeader{
			{Filename: "file1.txt"},
			{Filename: "file2.txt"},
		}
		err := formatBindData("query", out, data, "files", files, false, false)
		if err != nil {
			t.Fatalf("unexpected error: %v", err)
		}
		if len(data["files"]) != 2 {
			t.Fatalf("expected 2 files, got %d", len(data["files"]))
		}
	})

	t.Run("type casting error", func(t *testing.T) {
		t.Parallel()

		out := struct{}{}
		data := map[string][]int{} // Incorrect type to force a casting error
		err := formatBindData("query", out, data, "key", "value", false, false)
		require.Equal(t, "unsupported value type: string", err.Error())
	})
}

Domain

Subdomains

Frequently Asked Questions

What does TestFormatBindData() do?
TestFormatBindData() is a function in the fiber codebase, defined in binder/mapping_test.go.
Where is TestFormatBindData() defined?
TestFormatBindData() is defined in binder/mapping_test.go at line 246.

Analyze Your Own Codebase

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

Try Supermodel Free