|
14 | 14 |
|
15 | 15 | import unittest
|
16 | 16 |
|
| 17 | +from opentelemetry.exporter.prometheus_remote_write import ( |
| 18 | + PrometheusRemoteWriteMetricsExporter, |
| 19 | +) |
| 20 | + |
17 | 21 |
|
18 | 22 | class TestValidation(unittest.TestCase):
|
19 | 23 | # Test cases to ensure exporter parameter validation works as intended
|
20 | 24 | def test_valid_standard_param(self):
|
21 |
| - pass |
| 25 | + exporter = PrometheusRemoteWriteMetricsExporter( |
| 26 | + endpoint="/prom/test_endpoint", |
| 27 | + ) |
| 28 | + self.assertEqual(exporter.endpoint, "/prom/test_endpoint") |
22 | 29 |
|
23 | 30 | def test_valid_basic_auth_param(self):
|
24 |
| - pass |
25 |
| - |
26 |
| - def test_valid_bearer_token_param(self): |
27 |
| - pass |
| 31 | + exporter = PrometheusRemoteWriteMetricsExporter( |
| 32 | + endpoint="/prom/test_endpoint", |
| 33 | + basic_auth={ |
| 34 | + "username": "test_username", |
| 35 | + "password": "test_password", |
| 36 | + }, |
| 37 | + ) |
| 38 | + self.assertEqual(exporter.basic_auth["username"], "test_username") |
| 39 | + self.assertEqual(exporter.basic_auth["password"], "test_password") |
28 | 40 |
|
29 | 41 | def test_invalid_no_endpoint_param(self):
|
30 |
| - pass |
| 42 | + with self.assertRaises(ValueError): |
| 43 | + PrometheusRemoteWriteMetricsExporter("") |
31 | 44 |
|
32 | 45 | def test_invalid_no_username_param(self):
|
33 |
| - pass |
| 46 | + with self.assertRaises(ValueError): |
| 47 | + PrometheusRemoteWriteMetricsExporter( |
| 48 | + endpoint="/prom/test_endpoint", |
| 49 | + basic_auth={"password": "test_password"}, |
| 50 | + ) |
34 | 51 |
|
35 | 52 | def test_invalid_no_password_param(self):
|
36 |
| - pass |
| 53 | + with self.assertRaises(ValueError): |
| 54 | + PrometheusRemoteWriteMetricsExporter( |
| 55 | + endpoint="/prom/test_endpoint", |
| 56 | + basic_auth={"username": "test_username"}, |
| 57 | + ) |
37 | 58 |
|
38 | 59 | def test_invalid_conflicting_passwords_param(self):
|
39 |
| - pass |
40 |
| - |
41 |
| - def test_invalid_conflicting_bearer_tokens_param(self): |
42 |
| - pass |
43 |
| - |
44 |
| - def test_invalid_conflicting_auth_param(self): |
45 |
| - pass |
| 60 | + with self.assertRaises(ValueError): |
| 61 | + PrometheusRemoteWriteMetricsExporter( |
| 62 | + endpoint="/prom/test_endpoint", |
| 63 | + basic_auth={ |
| 64 | + "username": "test_username", |
| 65 | + "password": "test_password", |
| 66 | + "password_file": "test_file", |
| 67 | + }, |
| 68 | + ) |
| 69 | + |
| 70 | + def test_invalid_timeout_param(self): |
| 71 | + with self.assertRaises(ValueError): |
| 72 | + PrometheusRemoteWriteMetricsExporter( |
| 73 | + endpoint="/prom/test_endpoint", timeout=0 |
| 74 | + ) |
| 75 | + |
| 76 | + def test_valid_tls_config_param(self): |
| 77 | + tls_config = { |
| 78 | + "ca_file": "test_ca_file", |
| 79 | + "cert_file": "test_cert_file", |
| 80 | + "key_file": "test_key_file", |
| 81 | + "insecure_skip_verify": True, |
| 82 | + } |
| 83 | + exporter = PrometheusRemoteWriteMetricsExporter( |
| 84 | + endpoint="/prom/test_endpoint", tls_config=tls_config |
| 85 | + ) |
| 86 | + self.assertEqual(exporter.tls_config["ca_file"], tls_config["ca_file"]) |
| 87 | + self.assertEqual( |
| 88 | + exporter.tls_config["cert_file"], tls_config["cert_file"] |
| 89 | + ) |
| 90 | + self.assertEqual( |
| 91 | + exporter.tls_config["key_file"], tls_config["key_file"] |
| 92 | + ) |
| 93 | + self.assertEqual( |
| 94 | + exporter.tls_config["insecure_skip_verify"], |
| 95 | + tls_config["insecure_skip_verify"], |
| 96 | + ) |
| 97 | + |
| 98 | + # if cert_file is provided, then key_file must also be provided |
| 99 | + def test_invalid_tls_config_cert_only_param(self): |
| 100 | + tls_config = {"cert_file": "value"} |
| 101 | + with self.assertRaises(ValueError): |
| 102 | + PrometheusRemoteWriteMetricsExporter( |
| 103 | + endpoint="/prom/test_endpoint", tls_config=tls_config |
| 104 | + ) |
| 105 | + |
| 106 | + # if cert_file is provided, then key_file must also be provided |
| 107 | + def test_invalid_tls_config_key_only_param(self): |
| 108 | + tls_config = {"cert_file": "value"} |
| 109 | + with self.assertRaises(ValueError): |
| 110 | + PrometheusRemoteWriteMetricsExporter( |
| 111 | + endpoint="/prom/test_endpoint", tls_config=tls_config |
| 112 | + ) |
46 | 113 |
|
47 | 114 |
|
48 | 115 | class TestConversion(unittest.TestCase):
|
|
0 commit comments