1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

init tls test

This commit is contained in:
Darien Raymond 2016-12-16 21:39:00 +01:00
parent dd96b4eee7
commit 310474d592
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 89 additions and 0 deletions

View File

@ -67,3 +67,10 @@ func (v PortRange) ToPort() Port {
func (v PortRange) Contains(port Port) bool { func (v PortRange) Contains(port Port) bool {
return v.FromPort() <= port && port <= v.ToPort() return v.FromPort() <= port && port <= v.ToPort()
} }
func SinglePortRange(v Port) *PortRange {
return &PortRange{
From: uint32(v),
To: uint32(v),
}
}

View File

@ -0,0 +1,41 @@
package scenarios
import (
"github.com/golang/protobuf/proto"
"sync/atomic"
"time"
"v2ray.com/core"
v2net "v2ray.com/core/common/net"
)
var (
port uint32 = 50000
)
func pickPort() v2net.Port {
return v2net.Port(atomic.AddUint32(&port, 1))
}
func InitializeServerConfig(config *core.Config) error {
err := BuildV2Ray()
if err != nil {
return err
}
configBytes, err := proto.Marshal(config)
if err != nil {
return err
}
proc := RunV2RayProtobuf(configBytes)
err = proc.Start()
if err != nil {
return err
}
time.Sleep(time.Second)
runningServers = append(runningServers, proc)
return nil
}

View File

@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"bytes"
"v2ray.com/core/common/uuid" "v2ray.com/core/common/uuid"
) )
@ -32,3 +33,17 @@ func RunV2Ray(configFile string) *exec.Cmd {
return proc return proc
} }
func RunV2RayProtobuf(config []byte) *exec.Cmd {
GenTestBinaryPath()
covDir := filepath.Join(os.Getenv("GOPATH"), "out", "v2ray", "cov")
os.MkdirAll(covDir, os.ModeDir)
profile := uuid.New().String() + ".out"
proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb", "-test.run", "TestRunMainForCoverage", "-test.coverprofile", profile, "-test.outputdir", covDir)
proc.Stdin = bytes.NewBuffer(config)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
return proc
}

View File

@ -3,6 +3,7 @@
package scenarios package scenarios
import ( import (
"bytes"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -27,3 +28,13 @@ func RunV2Ray(configFile string) *exec.Cmd {
return proc return proc
} }
func RunV2RayProtobuf(config []byte) *exec.Cmd {
GenTestBinaryPath()
proc := exec.Command(testBinaryPath, "-config=stdin:", "-format=pb")
proc.Stdin = bytes.NewBuffer(config)
proc.Stderr = os.Stderr
proc.Stdout = os.Stdout
return proc
}

View File

@ -0,0 +1,15 @@
package scenarios
import (
"v2ray.com/core"
v2net "v2ray.com/core/common/net"
)
var clientConfig = &core.Config{
Inbound: []*core.InboundConnectionConfig{
{
PortRange: v2net.SinglePortRange(pickPort()),
ListenOn: v2net.NewIPOrDomain(v2net.LocalHostIP),
},
},
}