MCPcopy Index your code
hub / github.com/PasarGuard/node / TestMain

Function TestMain

controller/rpc/rpc_test.go:47–125  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

45}
46
47func TestMain(m *testing.M) {
48 // Setup
49 cfg := config.NewTestConfig(generatedConfigPath, apiKey)
50
51 tlsConfig, err := tlsutil.LoadTLSCredentials(sslCertFile, sslKeyFile)
52 if err != nil {
53 log.Fatalf("Failed to load TLS credentials: %v", err)
54 }
55
56 shutdownFunc, s, err := StartGRPCListener(tlsConfig, addr, cfg)
57 if err != nil {
58 log.Fatalf("Failed to start gRPC listener: %v", err)
59 }
60
61 certPool, err := tlsutil.LoadClientPool(sslCertFile)
62 if err != nil {
63 log.Fatalf("Failed to load client pool: %v", err)
64 }
65
66 creds := credentials.NewClientTLSFromCert(certPool, "")
67 // Set max message size to 64MB to match server configuration
68 const maxMsgSize = 64 * 1024 * 1024 // 64MB
69 opts := []grpc.DialOption{
70 grpc.WithTransportCredentials(creds),
71 grpc.WithDefaultCallOptions(
72 grpc.MaxCallRecvMsgSize(maxMsgSize),
73 grpc.MaxCallSendMsgSize(maxMsgSize),
74 ),
75 }
76
77 conn, err := grpc.NewClient(addr, opts...)
78 if err != nil {
79 log.Fatalf("Failed to connect to gRPC server: %v", err)
80 }
81
82 client := common.NewNodeServiceClient(conn)
83 md := metadata.Pairs("x-api-key", apiKey.String())
84 ctxWithSession := metadata.NewOutgoingContext(context.Background(), md)
85
86 configFile, err := os.ReadFile(configPath)
87 if err != nil {
88 log.Fatalf("Failed to read config file: %v", err)
89 }
90
91 ctx, cancel := context.WithTimeout(ctxWithSession, 5*time.Second)
92 _, err = client.Start(ctx, &common.Backend{
93 Type: common.BackendType_XRAY,
94 Config: string(configFile),
95 KeepAlive: 10,
96 })
97 cancel()
98 if err != nil {
99 log.Fatalf("Failed to start backend: %v", err)
100 }
101
102 sharedTestCtx = &testContext{
103 client: client,
104 ctxWithSession: ctxWithSession,

Callers

nothing calls this directly

Calls 9

StartMethod · 0.95
NewTestConfigFunction · 0.92
LoadTLSCredentialsFunction · 0.92
LoadClientPoolFunction · 0.92
NewNodeServiceClientFunction · 0.92
StartGRPCListenerFunction · 0.85
CloseMethod · 0.65
DisconnectMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected