|
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 | + try: |
| 26 | + PrometheusRemoteWriteMetricsExporter( |
| 27 | + endpoint="/prom/test_endpoint", |
| 28 | + ) |
| 29 | + except ValueError: |
| 30 | + self.fail("failed to instantiate exporter with valid params)") |
22 | 31 |
|
23 | 32 | def test_valid_basic_auth_param(self):
|
24 |
| - pass |
| 33 | + try: |
| 34 | + PrometheusRemoteWriteMetricsExporter( |
| 35 | + endpoint="/prom/test_endpoint", |
| 36 | + basic_auth={ |
| 37 | + "username": "test_username", |
| 38 | + "password": "test_password", |
| 39 | + }, |
| 40 | + ) |
| 41 | + except ValueError: |
| 42 | + self.fail("failed to instantiate exporter with valid params)") |
25 | 43 |
|
26 | 44 | def test_valid_bearer_token_param(self):
|
27 |
| - pass |
| 45 | + try: |
| 46 | + PrometheusRemoteWriteMetricsExporter( |
| 47 | + endpoint="/prom/test_endpoint", |
| 48 | + bearer_token="test_bearer_token", |
| 49 | + ) |
| 50 | + except ValueError: |
| 51 | + self.fail("failed to instantiate exporter with valid params)") |
28 | 52 |
|
29 | 53 | def test_invalid_no_endpoint_param(self):
|
30 |
| - pass |
| 54 | + with self.assertRaises(ValueError): |
| 55 | + PrometheusRemoteWriteMetricsExporter("") |
31 | 56 |
|
32 | 57 | def test_invalid_no_username_param(self):
|
33 |
| - pass |
| 58 | + with self.assertRaises(ValueError): |
| 59 | + PrometheusRemoteWriteMetricsExporter( |
| 60 | + endpoint="/prom/test_endpoint", |
| 61 | + basic_auth={"password": "test_password"}, |
| 62 | + ) |
34 | 63 |
|
35 | 64 | def test_invalid_no_password_param(self):
|
36 |
| - pass |
| 65 | + with self.assertRaises(ValueError): |
| 66 | + PrometheusRemoteWriteMetricsExporter( |
| 67 | + endpoint="/prom/test_endpoint", |
| 68 | + basic_auth={"username": "test_username"}, |
| 69 | + ) |
37 | 70 |
|
38 | 71 | def test_invalid_conflicting_passwords_param(self):
|
39 |
| - pass |
| 72 | + with self.assertRaises(ValueError): |
| 73 | + PrometheusRemoteWriteMetricsExporter( |
| 74 | + endpoint="/prom/test_endpoint", |
| 75 | + basic_auth={ |
| 76 | + "username": "test_username", |
| 77 | + "password": "test_password", |
| 78 | + "password_file": "test_file", |
| 79 | + }, |
| 80 | + ) |
40 | 81 |
|
41 | 82 | def test_invalid_conflicting_bearer_tokens_param(self):
|
42 |
| - pass |
| 83 | + with self.assertRaises(ValueError): |
| 84 | + PrometheusRemoteWriteMetricsExporter( |
| 85 | + endpoint="/prom/test_endpoint", |
| 86 | + bearer_token="test_bearer_token", |
| 87 | + bearer_token_file="test_file", |
| 88 | + ) |
43 | 89 |
|
44 | 90 | def test_invalid_conflicting_auth_param(self):
|
45 |
| - pass |
| 91 | + with self.assertRaises(ValueError): |
| 92 | + PrometheusRemoteWriteMetricsExporter( |
| 93 | + endpoint="/prom/test_endpoint", |
| 94 | + basic_auth={ |
| 95 | + "username": "test_username", |
| 96 | + "password": "test_password", |
| 97 | + }, |
| 98 | + bearer_token="test_bearer_token", |
| 99 | + ) |
46 | 100 |
|
47 | 101 |
|
48 | 102 | class TestConversion(unittest.TestCase):
|
|
0 commit comments