1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 03:37:37 -05:00
v2fly/testing/scenarios/server_env.go

77 lines
1.9 KiB
Go
Raw Normal View History

2015-12-04 10:49:10 -05:00
package scenarios
import (
2015-12-04 10:49:45 -05:00
"os"
"path/filepath"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/app/router/rules"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/shell/point"
// The following are neccesary as they register handlers in their init functions.
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
_ "github.com/v2ray/v2ray-core/proxy/freedom"
2016-01-24 15:48:38 -05:00
_ "github.com/v2ray/v2ray-core/proxy/http"
2016-01-28 07:40:00 -05:00
_ "github.com/v2ray/v2ray-core/proxy/shadowsocks"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/proxy/socks"
2015-12-07 14:32:38 -05:00
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
2015-12-04 10:49:10 -05:00
)
2015-12-04 11:32:42 -05:00
var (
2016-01-03 18:33:25 -05:00
runningServers = make([]*point.Point, 0, 10)
2015-12-04 11:32:42 -05:00
)
2015-12-04 10:49:10 -05:00
func TestFile(filename string) string {
2015-12-04 10:49:45 -05:00
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
2015-12-04 10:49:10 -05:00
}
2015-12-04 11:32:42 -05:00
func InitializeServerSetOnce(testcase string) error {
2016-01-28 07:40:00 -05:00
if err := InitializeServerServer(testcase); err != nil {
2015-12-04 11:32:42 -05:00
return err
}
2016-01-28 07:40:00 -05:00
if err := InitializeServerClient(testcase); err != nil {
2015-12-04 11:32:42 -05:00
return err
}
return nil
}
2016-01-28 07:40:00 -05:00
func InitializeServerServer(testcase string) error {
return InitializeServer(TestFile(testcase + "_server.json"))
}
func InitializeServerClient(testcase string) error {
return InitializeServer(TestFile(testcase + "_client.json"))
}
2015-12-04 10:49:10 -05:00
func InitializeServer(configFile string) error {
2016-01-17 15:43:10 -05:00
config, err := point.LoadConfig(configFile)
2015-12-04 10:49:10 -05:00
if err != nil {
2016-01-18 06:24:33 -05:00
log.Error("Failed to read config file (", configFile, "): ", configFile, err)
2015-12-04 10:49:10 -05:00
return err
}
vPoint, err := point.NewPoint(config)
if err != nil {
2016-01-18 06:24:33 -05:00
log.Error("Failed to create Point server: ", err)
2015-12-04 10:49:10 -05:00
return err
}
err = vPoint.Start()
if err != nil {
2016-01-18 06:24:33 -05:00
log.Error("Error starting Point server: ", err)
2015-12-04 10:49:10 -05:00
return err
}
2016-01-03 18:33:25 -05:00
runningServers = append(runningServers, vPoint)
2015-12-04 10:49:10 -05:00
return nil
}
2016-01-03 18:33:25 -05:00
func CloseAllServers() {
for _, server := range runningServers {
server.Close()
}
runningServers = make([]*point.Point, 0, 10)
}