github.com/cloudwego/hertz@v0.9.3/pkg/common/config/option_test.go (about)

     1  /*
     2   * Copyright 2022 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package config
    18  
    19  import (
    20  	"testing"
    21  	"time"
    22  
    23  	"github.com/cloudwego/hertz/pkg/app/server/registry"
    24  	"github.com/cloudwego/hertz/pkg/common/test/assert"
    25  )
    26  
    27  // TestDefaultOptions test options with default values
    28  func TestDefaultOptions(t *testing.T) {
    29  	options := NewOptions([]Option{})
    30  
    31  	assert.DeepEqual(t, defaultKeepAliveTimeout, options.KeepAliveTimeout)
    32  	assert.DeepEqual(t, defaultReadTimeout, options.ReadTimeout)
    33  	assert.DeepEqual(t, defaultReadTimeout, options.IdleTimeout)
    34  	assert.DeepEqual(t, time.Duration(0), options.WriteTimeout)
    35  	assert.True(t, options.RedirectTrailingSlash)
    36  	assert.True(t, options.RedirectTrailingSlash)
    37  	assert.False(t, options.HandleMethodNotAllowed)
    38  	assert.False(t, options.UseRawPath)
    39  	assert.False(t, options.RemoveExtraSlash)
    40  	assert.True(t, options.UnescapePathValues)
    41  	assert.False(t, options.DisablePreParseMultipartForm)
    42  	assert.False(t, options.SenseClientDisconnection)
    43  	assert.DeepEqual(t, defaultNetwork, options.Network)
    44  	assert.DeepEqual(t, defaultAddr, options.Addr)
    45  	assert.DeepEqual(t, defaultMaxRequestBodySize, options.MaxRequestBodySize)
    46  	assert.False(t, options.GetOnly)
    47  	assert.False(t, options.DisableKeepalive)
    48  	assert.False(t, options.NoDefaultServerHeader)
    49  	assert.DeepEqual(t, defaultWaitExitTimeout, options.ExitWaitTimeout)
    50  	assert.Nil(t, options.TLS)
    51  	assert.DeepEqual(t, defaultReadBufferSize, options.ReadBufferSize)
    52  	assert.False(t, options.ALPN)
    53  	assert.False(t, options.H2C)
    54  	assert.DeepEqual(t, []interface{}{}, options.Tracers)
    55  	assert.DeepEqual(t, new(interface{}), options.TraceLevel)
    56  	assert.DeepEqual(t, registry.NoopRegistry, options.Registry)
    57  	assert.Nil(t, options.BindConfig)
    58  	assert.Nil(t, options.ValidateConfig)
    59  	assert.Nil(t, options.CustomBinder)
    60  	assert.Nil(t, options.CustomValidator)
    61  	assert.DeepEqual(t, false, options.DisableHeaderNamesNormalizing)
    62  }
    63  
    64  // TestApplyCustomOptions test apply options with custom values after init
    65  func TestApplyCustomOptions(t *testing.T) {
    66  	options := NewOptions([]Option{})
    67  	options.Apply([]Option{
    68  		{F: func(o *Options) {
    69  			o.Network = "unix"
    70  		}},
    71  	})
    72  	assert.DeepEqual(t, "unix", options.Network)
    73  }