V2bX/node/controller/node_test.go

81 lines
2.0 KiB
Go
Raw Normal View History

2022-10-09 23:31:15 -04:00
package controller_test
2022-06-01 13:35:41 -04:00
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
2022-09-14 21:24:14 -04:00
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
_ "github.com/Yuzuki616/V2bX/core/distro/all"
2022-10-09 23:31:15 -04:00
. "github.com/Yuzuki616/V2bX/node/controller"
2022-09-14 21:24:14 -04:00
xCore "github.com/xtls/xray-core/core"
coreConf "github.com/xtls/xray-core/infra/conf"
2022-06-01 13:35:41 -04:00
"os"
"os/signal"
"runtime"
"syscall"
"testing"
)
func TestController(t *testing.T) {
2022-09-14 21:24:14 -04:00
serverConfig := &coreConf.Config{
Stats: &coreConf.StatsConfig{},
LogConfig: &coreConf.LogConfig{LogLevel: "debug"},
2022-06-01 13:35:41 -04:00
}
2022-09-14 21:24:14 -04:00
policyConfig := &coreConf.PolicyConfig{}
policyConfig.Levels = map[uint32]*coreConf.Policy{0: &coreConf.Policy{
2022-06-01 13:35:41 -04:00
StatsUserUplink: true,
StatsUserDownlink: true,
}}
serverConfig.Policy = policyConfig
config, _ := serverConfig.Build()
// config := &core.Config{
// App: []*serial.TypedMessage{
// serial.ToTypedMessage(&dispatcher.Config{}),
// serial.ToTypedMessage(&proxyman.InboundConfig{}),
// serial.ToTypedMessage(&proxyman.OutboundConfig{}),
// serial.ToTypedMessage(&stats.Config{}),
// }}
2022-09-14 21:24:14 -04:00
server, err := xCore.New(config)
2022-06-01 13:35:41 -04:00
defer server.Close()
if err != nil {
t.Errorf("failed to create instance: %s", err)
}
if err = server.Start(); err != nil {
t.Errorf("Failed to start instance: %s", err)
}
2022-09-14 21:24:14 -04:00
certConfig := &conf.CertConfig{
2022-06-01 13:35:41 -04:00
CertMode: "http",
CertDomain: "test.ss.tk",
Provider: "alidns",
Email: "ss@ss.com",
}
2022-09-14 21:24:14 -04:00
controlerconfig := &conf.ControllerConfig{
2022-06-01 13:35:41 -04:00
UpdatePeriodic: 5,
CertConfig: certConfig,
}
2022-09-14 21:24:14 -04:00
apiConfig := &conf.ApiConfig{
2022-06-01 13:35:41 -04:00
APIHost: "http://127.0.0.1:667",
Key: "123",
NodeID: 41,
NodeType: "V2ray",
}
apiclient := panel.New(apiConfig)
2022-09-14 21:24:14 -04:00
c := &core.Core{Server: server}
c.Start()
node := New(c, apiclient, controlerconfig)
2022-06-01 13:35:41 -04:00
fmt.Println("Sleep 1s")
2022-09-14 21:24:14 -04:00
err = node.Start()
2022-06-01 13:35:41 -04:00
if err != nil {
t.Error(err)
}
//Explicitly triggering GC to remove garbage from config loading.
runtime.GC()
{
osSignals := make(chan os.Signal, 1)
2022-09-14 21:24:14 -04:00
signal.Notify(osSignals, syscall.SIGINT, syscall.SIGKILL, syscall.SIGTERM)
2022-06-01 13:35:41 -04:00
<-osSignals
}
}