def test_fields(self, mock_get_current_span, mock_invalid_span_context): mock_get_current_span.configure_mock( return_value=Mock( **{ "get_span_context.return_value": Mock( **{ "trace_id": 1, "span_id": 2, "trace_flags": 3, "trace_state": TraceState([("a", "b")]), } ) } ) ) mock_setter = Mock() FORMAT.inject({}, setter=mock_setter) inject_fields = set() for mock_call in mock_setter.mock_calls: inject_fields.add(mock_call[1][1]) self.assertEqual(inject_fields, FORMAT.fields)
def test_tracestate_update_invalid(self): state = TraceState([("a", "1")]) new_state = state.update("a", "2=/") self.assertNotEqual(new_state.get("a"), "2=/") new_state = new_state.update("a", ",,2,,f") self.assertNotEqual(new_state.get("a"), ",,2,,f") self.assertEqual(new_state.get("a"), "1")
def test_tracestate_add_invalid(self): state = TraceState() new_state = state.add("%%%nsasa", "val") self.assertEqual(len(new_state), 0) new_state = new_state.add("key", "====val====") self.assertEqual(len(new_state), 0) self.assertEqual(new_state.to_header(), "")
def test_tracestate_delete_preserved(self): state = TraceState([("a", "1"), ("b", "2"), ("c", "3")]) new_state = state.delete("b") self.assertIsNone(new_state.get("b")) entries = list(new_state.items()) a_place = entries.index(("a", "1")) c_place = entries.index(("c", "3")) self.assertLessEqual(a_place, c_place)
def test_tracestate_valid_pairs(self): pairs = [("1a-2f@foo", "bar1"), ("foo-_*/bar", "bar4")] state = TraceState(pairs) self.assertEqual(len(state), 2) self.assertIsNotNone(state.get("foo-_*/bar")) self.assertEqual(state.get("foo-_*/bar"), "bar4") self.assertEqual(state.to_header(), "1a-2f@foo=bar1,foo-_*/bar=bar4") self.assertIsNone(state.get("random"))
def test_tracestate_update_valid(self): state = TraceState([("a", "1")]) new_state = state.update("a", "2") self.assertEqual(new_state.get("a"), "2") new_state = new_state.add("b", "3") self.assertNotEqual(state, new_state)
def test_tracestate_add_valid(self): state = TraceState() new_state = state.add("1a-2f@foo", "bar4") self.assertEqual(len(new_state), 1) self.assertEqual(new_state.get("1a-2f@foo"), "bar4")
def test_empty_tracestate(self): state = TraceState() self.assertEqual(len(state), 0) self.assertEqual(state.to_header(), "")