github.com/swiftstack/proxyfs@v0.0.0-20201223034610-5434d919416e/pfs_middleware/tests/test_utils.py (about) 1 # Copyright (c) 2016-2017 SwiftStack, Inc. 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 12 # implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 import unittest 17 import pfs_middleware.utils as utils 18 19 20 class TestHelperFunctions(unittest.TestCase): 21 def test_extract_errno(self): 22 self.assertEqual(2, utils.extract_errno("errno: 2")) 23 self.assertEqual(17, utils.extract_errno("errno: 17")) 24 self.assertEqual(None, utils.extract_errno("it broke")) 25 26 def test_parse_path(self): 27 self.assertEqual( 28 utils.parse_path("/v1/a/c/o"), 29 ["v1", "a", "c", "o"]) 30 self.assertEqual( 31 utils.parse_path("/v1/a/c/obj/with/slashes"), 32 ["v1", "a", "c", "obj/with/slashes"]) 33 self.assertEqual( 34 utils.parse_path("/v1/a/c/obj/trailing/slashes///"), 35 ["v1", "a", "c", "obj/trailing/slashes///"]) 36 self.assertEqual( 37 utils.parse_path("/v1/a/c/"), 38 ["v1", "a", "c", None]) 39 self.assertEqual( 40 utils.parse_path("/v1/a/c"), 41 ["v1", "a", "c", None]) 42 self.assertEqual( 43 utils.parse_path("/v1/a/"), 44 ["v1", "a", None, None]) 45 self.assertEqual( 46 utils.parse_path("/v1/a"), 47 ["v1", "a", None, None]) 48 self.assertEqual( 49 utils.parse_path("/info"), 50 ["info", None, None, None]) 51 self.assertEqual( 52 utils.parse_path("/"), 53 [None, None, None, None])