init tls test

pull/330/head
Darien Raymond 8 years ago
parent dd96b4eee7
commit 310474d592
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

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

@ -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
}

@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"bytes"
"v2ray.com/core/common/uuid"
)
@ -32,3 +33,17 @@ func RunV2Ray(configFile string) *exec.Cmd {
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
}

@ -3,6 +3,7 @@
package scenarios
import (
"bytes"
"fmt"
"os"
"os/exec"
@ -27,3 +28,13 @@ func RunV2Ray(configFile string) *exec.Cmd {
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
}

@ -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),
},
},
}
Loading…
Cancel
Save