1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 09:57:04 -04:00
v2fly/testing/scenarios/server_env.go

78 lines
2.1 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
2015-12-07 16:47:47 -05:00
_ "github.com/v2ray/v2ray-core/app/router/json"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/app/router/rules"
2015-12-07 16:47:47 -05:00
_ "github.com/v2ray/v2ray-core/app/router/rules/json"
2015-12-04 10:49:10 -05:00
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/shell/point"
2015-12-06 10:41:41 -05:00
pointjson "github.com/v2ray/v2ray-core/shell/point/json"
2015-12-04 10:49:10 -05:00
// The following are neccesary as they register handlers in their init functions.
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
2015-12-06 12:21:15 -05:00
_ "github.com/v2ray/v2ray-core/proxy/blackhole/json"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
2015-12-06 12:21:15 -05:00
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/json"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/proxy/freedom"
2015-12-06 12:21:15 -05:00
_ "github.com/v2ray/v2ray-core/proxy/freedom/json"
2015-12-04 10:49:10 -05:00
_ "github.com/v2ray/v2ray-core/proxy/socks"
2015-12-06 12:21:15 -05:00
_ "github.com/v2ray/v2ray-core/proxy/socks/json"
2015-12-07 14:32:38 -05:00
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/inbound/json"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound"
_ "github.com/v2ray/v2ray-core/proxy/vmess/outbound/json"
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 {
err := InitializeServer(TestFile(testcase + "_server.json"))
if err != nil {
return err
}
err = InitializeServer(TestFile(testcase + "_client.json"))
if err != nil {
return err
}
return nil
}
2015-12-04 10:49:10 -05:00
func InitializeServer(configFile string) error {
2015-12-06 10:41:41 -05:00
config, err := pointjson.LoadConfig(configFile)
2015-12-04 10:49:10 -05:00
if err != nil {
log.Error("Failed to read config file (%s): %v", configFile, err)
return err
}
vPoint, err := point.NewPoint(config)
if err != nil {
log.Error("Failed to create Point server: %v", err)
return err
}
err = vPoint.Start()
if err != nil {
log.Error("Error starting Point server: %v", err)
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)
}