v2ray-core/testing/scenarios/server_env.go

72 lines
1.9 KiB
Go
Raw Normal View History

2015-12-04 15:49:10 +00:00
package scenarios
import (
2015-12-04 15:49:45 +00:00
"os"
"path/filepath"
2015-12-04 15:49:10 +00:00
_ "github.com/v2ray/v2ray-core/app/router/config/json"
_ "github.com/v2ray/v2ray-core/app/router/rules"
_ "github.com/v2ray/v2ray-core/app/router/rules/config/json"
"github.com/v2ray/v2ray-core/common/log"
"github.com/v2ray/v2ray-core/shell/point"
2015-12-06 15:41:41 +00:00
pointjson "github.com/v2ray/v2ray-core/shell/point/json"
2015-12-04 15:49:10 +00:00
// 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/blackhole/config/json"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/config/json"
_ "github.com/v2ray/v2ray-core/proxy/freedom"
_ "github.com/v2ray/v2ray-core/proxy/freedom/config/json"
_ "github.com/v2ray/v2ray-core/proxy/socks"
_ "github.com/v2ray/v2ray-core/proxy/socks/config/json"
_ "github.com/v2ray/v2ray-core/proxy/vmess"
_ "github.com/v2ray/v2ray-core/proxy/vmess/config/json"
)
2015-12-04 16:32:42 +00:00
var (
serverup = make(map[string]bool)
)
2015-12-04 15:49:10 +00:00
func TestFile(filename string) string {
2015-12-04 15:49:45 +00:00
return filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "v2ray", "v2ray-core", "testing", "scenarios", "data", filename)
2015-12-04 15:49:10 +00:00
}
2015-12-04 16:32:42 +00:00
func InitializeServerSetOnce(testcase string) error {
if up, found := serverup[testcase]; found && up {
return nil
}
err := InitializeServer(TestFile(testcase + "_server.json"))
if err != nil {
return err
}
err = InitializeServer(TestFile(testcase + "_client.json"))
if err != nil {
return err
}
serverup[testcase] = true
return nil
}
2015-12-04 15:49:10 +00:00
func InitializeServer(configFile string) error {
2015-12-06 15:41:41 +00:00
config, err := pointjson.LoadConfig(configFile)
2015-12-04 15:49:10 +00: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
}
return nil
}