(m *testing.M)
| 47 | } |
| 48 | |
| 49 | func 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) |
nothing calls this directly
no test coverage detected