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

Function TestMain

controller/rest/rest_test.go:49–210  ·  view source on GitHub ↗
(m *testing.M)

Source from the content-addressed store, hash-verified

47}
48
49func TestMain(m *testing.M) {
50 // Setup
51 cfg := config.NewTestConfig(generatedConfigPath, apiKey)
52
53 tlsConfig, err := tlsutil.LoadTLSCredentials(sslCertFile, sslKeyFile)
54 if err != nil {
55 log.Fatalf("Failed to load TLS credentials: %v", err)
56 }
57
58 shutdownFunc, s, err := StartHttpListener(tlsConfig, addr, cfg)
59 if err != nil {
60 log.Fatalf("Failed to start HTTP listener: %v", err)
61 }
62
63 certPool, err := tlsutil.LoadClientPool(sslCertFile)
64 if err != nil {
65 log.Fatalf("Failed to load client pool: %v", err)
66 }
67 client := tlsutil.CreateHTTPClient(certPool, nodeHost)
68
69 url := fmt.Sprintf("https://%s", addr)
70
71 createAuthenticatedRequest := func(method, endpoint string, data proto.Message, response proto.Message) error {
72 body, err := proto.Marshal(data)
73 if err != nil {
74 return err
75 }
76
77 req, err := http.NewRequest(method, url+endpoint, bytes.NewBuffer(body))
78 if err != nil {
79 return err
80 }
81 req.Header.Set("x-api-key", apiKey.String())
82 if body != nil {
83 req.Header.Set("Content-Type", "application/x-protobuf")
84 }
85
86 do, err := client.Do(req)
87 if err != nil {
88 return err
89 }
90 defer do.Body.Close()
91
92 responseBody, _ := io.ReadAll(do.Body)
93 if err = proto.Unmarshal(responseBody, response); err != nil {
94 return err
95 }
96 return nil
97 }
98
99 createAuthenticatedStreamingRequest := func(method, endpoint string) (io.ReadCloser, error) {
100 req, err := http.NewRequest(method, url+endpoint, nil)
101 if err != nil {
102 return nil, err
103 }
104 req.Header.Set("x-api-key", apiKey.String())
105
106 resp, err := client.Do(req)

Callers

nothing calls this directly

Calls 9

NewTestConfigFunction · 0.92
LoadTLSCredentialsFunction · 0.92
LoadClientPoolFunction · 0.92
CreateHTTPClientFunction · 0.92
StartHttpListenerFunction · 0.85
NewRequestMethod · 0.80
CloseMethod · 0.65
DisconnectMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected