Kaynağa Gözat

test case for allocation config

Darien Raymond 9 yıl önce
ebeveyn
işleme
be57f48bb3
2 değiştirilmiş dosya ile 27 ekleme ve 10 silme
  1. 1 1
      shell/point/config_json.go
  2. 26 9
      shell/point/config_json_test.go

+ 1 - 1
shell/point/config_json.go

@@ -129,7 +129,7 @@ func (this *InboundDetourConfig) UnmarshalJSON(data []byte) error {
 		}
 	}
 	if this.Allocation.Strategy == AllocationStrategyRandom {
-		if this.Allocation.Refresh == 0 {
+		if this.Allocation.Refresh == DefaultRefreshMinute {
 			this.Allocation.Refresh = 5
 		}
 		if this.Allocation.Concurrency == 0 {

+ 26 - 9
shell/point/config_json_test.go

@@ -3,16 +3,13 @@
 package point_test
 
 import (
+	"encoding/json"
+	"os"
 	"path/filepath"
 	"testing"
 
 	_ "github.com/v2ray/v2ray-core/app/router/rules"
 	netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
-	_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
-	_ "github.com/v2ray/v2ray-core/proxy/freedom"
-	_ "github.com/v2ray/v2ray-core/proxy/socks"
-	_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
-	_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
 	. "github.com/v2ray/v2ray-core/shell/point"
 
 	v2testing "github.com/v2ray/v2ray-core/testing"
@@ -22,8 +19,8 @@ import (
 func TestClientSampleConfig(t *testing.T) {
 	v2testing.Current(t)
 
-	// TODO: fix for Windows
-	baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
+	GOPATH := os.Getenv("GOPATH")
+	baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
 
 	pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_socks_vmess.json"))
 	assert.Error(err).IsNil()
@@ -42,8 +39,8 @@ func TestClientSampleConfig(t *testing.T) {
 func TestServerSampleConfig(t *testing.T) {
 	v2testing.Current(t)
 
-	// TODO: fix for Windows
-	baseDir := "$GOPATH/src/github.com/v2ray/v2ray-core/release/config"
+	GOPATH := os.Getenv("GOPATH")
+	baseDir := filepath.Join(GOPATH, "src", "github.com", "v2ray", "v2ray-core", "release", "config")
 
 	pointConfig, err := LoadConfig(filepath.Join(baseDir, "vpoint_vmess_freedom.json"))
 	assert.Error(err).IsNil()
@@ -58,3 +55,23 @@ func TestServerSampleConfig(t *testing.T) {
 	assert.StringLiteral(pointConfig.OutboundConfig.Protocol).Equals("freedom")
 	assert.Pointer(pointConfig.OutboundConfig.Settings).IsNotNil()
 }
+
+func TestDefaultValueOfRandomAllocation(t *testing.T) {
+	v2testing.Current(t)
+
+	rawJson := `{
+    "protocol": "vmess",
+    "port": 1,
+    "settings": {},
+    "allocate": {
+      "strategy": "random"
+    }
+  }`
+
+	inboundDetourConfig := new(InboundDetourConfig)
+	err := json.Unmarshal([]byte(rawJson), inboundDetourConfig)
+	assert.Error(err).IsNil()
+	assert.StringLiteral(inboundDetourConfig.Allocation.Strategy).Equals(AllocationStrategyRandom)
+	assert.Int(inboundDetourConfig.Allocation.Concurrency).Equals(3)
+	assert.Int(inboundDetourConfig.Allocation.Refresh).Equals(5)
+}