From f17b8df79498b55c9396b21b616d7182e7705002 Mon Sep 17 00:00:00 2001 From: Connor Adams Date: Fri, 3 Jul 2020 16:36:57 -0400 Subject: [PATCH] regex tests --- .../tests/util/test_exclude_list.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 opentelemetry-api/tests/util/test_exclude_list.py diff --git a/opentelemetry-api/tests/util/test_exclude_list.py b/opentelemetry-api/tests/util/test_exclude_list.py new file mode 100644 index 00000000000..9e49dbf144d --- /dev/null +++ b/opentelemetry-api/tests/util/test_exclude_list.py @@ -0,0 +1,57 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from unittest import mock + +from opentelemetry.util import ExcludeList + + +class TestExcludeList(unittest.TestCase): + def test_basic(self): + regexes = ExcludeList(["path/123", "http://site.com/other_path"]) + self.assertTrue(regexes.url_disabled("http://site.com/path/123")) + self.assertTrue(regexes.url_disabled("http://site.com/path/123/abc")) + self.assertTrue(regexes.url_disabled("https://site.com/path/123?arg=other")) + + self.assertFalse(regexes.url_disabled("https://site.com/path/abc/123")) + self.assertFalse(regexes.url_disabled("https://site.com/path")) + + self.assertTrue(regexes.url_disabled("http://site.com/other_path")) + self.assertTrue(regexes.url_disabled("http://site.com/other_path?abc")) + + self.assertFalse(regexes.url_disabled("https://site.com/other_path")) + self.assertFalse(regexes.url_disabled("https://site.com/abc/other_path")) + + def test_regex(self): + regexes = ExcludeList( + [r"^https?://site\.com/path/123$", r"^http://.*\?arg=foo"] + ) + + self.assertTrue(regexes.url_disabled("http://site.com/path/123")) + self.assertTrue(regexes.url_disabled("https://site.com/path/123")) + + self.assertFalse(regexes.url_disabled("http://site.com/path/123/abc")) + self.assertFalse(regexes.url_disabled("http://site,com/path/123")) + + self.assertTrue( + regexes.url_disabled("http://site.com/path/123?arg=foo") + ) + self.assertTrue( + regexes.url_disabled("http://site.com/path/123?arg=foo,arg2=foo2") + ) + + self.assertFalse( + regexes.url_disabled("https://site.com/path/123?arg=foo") + )