Home / Function/ Test_Ctx_Subdomains() — fiber Function Reference

Test_Ctx_Subdomains() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

ctx_test.go lines 4926–5051

func Test_Ctx_Subdomains(t *testing.T) {
	app := New()

	type tc struct {
		name   string
		host   string
		offset []int // nil ⇒ call without argument
		want   []string
	}

	cases := []tc{
		{
			name:   "default offset (2) drops registrable domain + TLD",
			host:   "john.doe.is.awesome.google.com",
			offset: nil, // Subdomains()
			want:   []string{"john", "doe", "is", "awesome"},
		},
		{
			name:   "custom offset trims N right-hand labels",
			host:   "john.doe.is.awesome.google.com",
			offset: []int{4},
			want:   []string{"john", "doe"},
		},
		{
			name:   "offset too high returns empty",
			host:   "john.doe.is.awesome.google.com",
			offset: []int{10},
			want:   []string{},
		},
		{
			name:   "zero offset returns all labels",
			host:   "john.doe.google.com",
			offset: []int{0},
			want:   []string{"john", "doe", "google", "com"},
		},
		{
			name:   "offset 1 keeps registrable domain",
			host:   "john.doe.google.com",
			offset: []int{1},
			want:   []string{"john", "doe", "google"},
		},
		{
			name:   "negative offset returns empty",
			host:   "john.doe.google.com",
			offset: []int{-1},
			want:   []string{},
		},
		{
			name:   "offset equal len returns empty",
			host:   "john.doe.com",
			offset: []int{3},
			want:   []string{},
		},
		{
			name:   "offset equal len returns empty",
			host:   "john.doe.com",
			offset: []int{3},
			want:   []string{},
		},
		{
			name:   "zero offset returns all labels with port present",
			host:   "localhost:3000",
			offset: []int{0},
			want:   []string{"localhost"},
		},
		{
			name:   "host with port — custom offset trims 2 labels",
			host:   "foo.bar.example.com:8080",
			offset: []int{2},
			want:   []string{"foo", "bar"},
		},
		{
			name:   "fully qualified domain trims trailing dot",
			host:   "john.doe.example.com.",
			offset: nil,
			want:   []string{"john", "doe"},
		},
		{
			name:   "punycode domain is decoded",
			host:   "xn--bcher-kva.example.com",
			offset: nil,

Domain

Subdomains

Defined In

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free