mekya_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package scenarios
  2. import (
  3. "context"
  4. "os"
  5. "testing"
  6. "time"
  7. "github.com/v2fly/v2ray-core/v5/common"
  8. "github.com/v2fly/v2ray-core/v5/testing/servers/tcp"
  9. _ "github.com/v2fly/v2ray-core/v5/main/distro/all"
  10. )
  11. func TestMekya(t *testing.T) {
  12. tcpServer := tcp.Server{
  13. MsgProcessor: xor,
  14. }
  15. dest, err := tcpServer.Start()
  16. common.Must(err)
  17. defer tcpServer.Close()
  18. coreInst, InstMgrIfce := NewInstanceManagerCoreInstance()
  19. defer coreInst.Close()
  20. common.Must(InstMgrIfce.AddInstance(
  21. context.TODO(),
  22. "mekya_client",
  23. common.Must2(os.ReadFile("config/mekya_client.json")).([]byte),
  24. "jsonv5"))
  25. common.Must(InstMgrIfce.AddInstance(
  26. context.TODO(),
  27. "mekya_server",
  28. common.Must2(os.ReadFile("config/mekya_server.json")).([]byte),
  29. "jsonv5"))
  30. common.Must(InstMgrIfce.StartInstance(context.TODO(), "mekya_server"))
  31. common.Must(InstMgrIfce.StartInstance(context.TODO(), "mekya_client"))
  32. defer func() {
  33. common.Must(InstMgrIfce.StopInstance(context.TODO(), "mekya_server"))
  34. common.Must(InstMgrIfce.StopInstance(context.TODO(), "mekya_client"))
  35. common.Must(InstMgrIfce.UntrackInstance(context.TODO(), "mekya_server"))
  36. common.Must(InstMgrIfce.UntrackInstance(context.TODO(), "mekya_client"))
  37. coreInst.Close()
  38. }()
  39. if err := testTCPConnViaSocks(17774, dest.Port, 1024, time.Second*2)(); err != nil {
  40. t.Error(err)
  41. }
  42. }