Home / Function/ Test_Ctx_Port_RemoteAddrVariants() — fiber Function Reference

Test_Ctx_Port_RemoteAddrVariants() — fiber Function Reference

Architecture documentation for the Test_Ctx_Port_RemoteAddrVariants() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  f3aa4232_e0cb_e274_a6bd_8fa0610d2de4["Test_Ctx_Port_RemoteAddrVariants()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  f3aa4232_e0cb_e274_a6bd_8fa0610d2de4 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style f3aa4232_e0cb_e274_a6bd_8fa0610d2de4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 2771–2826

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

	tests := []struct {
		name   string
		remote net.Addr
		want   string
	}{
		{
			name: "tcp",
			remote: &net.TCPAddr{
				IP:   net.IPv4(127, 0, 0, 1),
				Port: 8080,
			},
			want: "8080",
		},
		{
			name:   "unix",
			remote: &net.UnixAddr{Name: "/tmp/fiber.sock", Net: "unix"},
			want:   "",
		},
		{
			name:   "default-remote",
			remote: nil,
			want:   "0",
		},
		{
			name:   "string-host-port",
			remote: testNetAddr{network: "tcp", address: "192.0.2.1:443"},
			want:   "443",
		},
		{
			name:   "string-missing-port",
			remote: testNetAddr{network: "tcp", address: "192.0.2.1"},
			want:   "",
		},
		{
			name:   "string-ipv6-port",
			remote: testNetAddr{network: "tcp", address: "[2001:db8::1]:8443"},
			want:   "8443",
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			t.Parallel()
			app := New()
			ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
			defaultCtx, ok := ctx.(*DefaultCtx)
			require.True(t, ok)
			defaultCtx.fasthttp.SetRemoteAddr(test.remote)
			require.Equal(t, test.want, ctx.Port())
			app.ReleaseCtx(ctx)
		})
	}
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Ctx_Port_RemoteAddrVariants() do?
Test_Ctx_Port_RemoteAddrVariants() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Port_RemoteAddrVariants() defined?
Test_Ctx_Port_RemoteAddrVariants() is defined in ctx_test.go at line 2771.

Analyze Your Own Codebase

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

Try Supermodel Free