mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
init tls test
This commit is contained in:
parent
dd96b4eee7
commit
310474d592
@ -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),
|
||||
}
|
||||
}
|
||||
|
41
testing/scenarios/common.go
Normal file
41
testing/scenarios/common.go
Normal 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
|
||||
}
|
@ -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
|
||||
}
|
||||
|
15
testing/scenarios/tls_test.go
Normal file
15
testing/scenarios/tls_test.go
Normal 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),
|
||||
},
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue
Block a user