|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from unittest import TestCase |
| 16 | + |
| 17 | +from opentelemetry.instrumentation.asgi import CarrierGetter |
| 18 | + |
| 19 | + |
| 20 | +class TestCarrierGetter(TestCase): |
| 21 | + def test_get_none(self): |
| 22 | + getter = CarrierGetter() |
| 23 | + carrier = {} |
| 24 | + val = getter.get(carrier, "test") |
| 25 | + self.assertIsNone(val) |
| 26 | + |
| 27 | + def test_get_(self): |
| 28 | + getter = CarrierGetter() |
| 29 | + carrier = {"headers": [(b"test-key", b"val")]} |
| 30 | + expected_val = ["val"] |
| 31 | + self.assertEqual( |
| 32 | + getter.get(carrier, "Test-Key"), |
| 33 | + expected_val, |
| 34 | + "Should be case insensitive", |
| 35 | + ) |
| 36 | + self.assertEqual( |
| 37 | + getter.get(carrier, "test-key"), |
| 38 | + expected_val, |
| 39 | + "Should be case insensitive", |
| 40 | + ) |
| 41 | + self.assertEqual( |
| 42 | + getter.get(carrier, "TEST-KEY"), |
| 43 | + expected_val, |
| 44 | + "Should be case insensitive", |
| 45 | + ) |
| 46 | + |
| 47 | + def test_keys(self): |
| 48 | + getter = CarrierGetter() |
| 49 | + keys = getter.keys({}) |
| 50 | + self.assertEqual(keys, []) |
0 commit comments