github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/policy_test.go (about)

     1  package conf_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"v2ray.com/core/common"
     7  	. "v2ray.com/core/infra/conf"
     8  )
     9  
    10  func TestBufferSize(t *testing.T) {
    11  	cases := []struct {
    12  		Input  int32
    13  		Output int32
    14  	}{
    15  		{
    16  			Input:  0,
    17  			Output: 0,
    18  		},
    19  		{
    20  			Input:  -1,
    21  			Output: -1,
    22  		},
    23  		{
    24  			Input:  1,
    25  			Output: 1024,
    26  		},
    27  	}
    28  
    29  	for _, c := range cases {
    30  		bs := int32(c.Input)
    31  		rate := uint64(c.Input)
    32  		pConf := Policy{
    33  			BufferSize: &bs,
    34  			Rate:       &rate,
    35  		}
    36  		p, err := pConf.Build()
    37  		common.Must(err)
    38  		if p.Buffer.Connection != c.Output {
    39  			t.Error("expected buffer size ", c.Output, " but got ", p.Buffer.Connection)
    40  		}
    41  	}
    42  }