David Ostrovsky | 2b5fe09 | 2021-03-03 11:52:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 2 | # Copyright (C) 2013 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | import unittest |
| 17 | from util import resolve_url |
| 18 | |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 19 | |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 20 | class TestResolveUrl(unittest.TestCase): |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 21 | """ run to test: |
| 22 | python -m unittest -v util_test |
| 23 | """ |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 24 | |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 25 | def testKnown(self): |
| 26 | url = resolve_url('GERRIT:foo.jar', {}) |
Chad Horohoe | 6914232 | 2018-05-17 10:19:22 -0700 | [diff] [blame] | 27 | self.assertEqual(url, |
| 28 | 'http://gerrit-maven.storage.googleapis.com/foo.jar') |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 29 | |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 30 | def testKnownRedirect(self): |
| 31 | url = resolve_url('MAVEN_CENTRAL:foo.jar', |
David Pursehouse | 4dab1bb | 2019-04-23 19:41:20 +0900 | [diff] [blame] | 32 | {'MAVEN_CENTRAL': 'https://my.company.mirror/maven2'}) |
| 33 | self.assertEqual(url, 'https://my.company.mirror/maven2/foo.jar') |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 34 | |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 35 | def testCustom(self): |
David Pursehouse | 4dab1bb | 2019-04-23 19:41:20 +0900 | [diff] [blame] | 36 | url = resolve_url('https://maven.example.com/release/foo.jar', {}) |
| 37 | self.assertEqual(url, 'https://maven.example.com/release/foo.jar') |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 38 | |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 39 | def testCustomRedirect(self): |
| 40 | url = resolve_url('MAVEN_EXAMPLE:foo.jar', |
Chad Horohoe | 6914232 | 2018-05-17 10:19:22 -0700 | [diff] [blame] | 41 | {'MAVEN_EXAMPLE': |
David Pursehouse | 4dab1bb | 2019-04-23 19:41:20 +0900 | [diff] [blame] | 42 | 'https://maven.example.com/release'}) |
| 43 | self.assertEqual(url, 'https://maven.example.com/release/foo.jar') |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 44 | |
David Ostrovsky | 2536d06 | 2013-11-14 00:35:07 +0100 | [diff] [blame] | 45 | |
| 46 | if __name__ == '__main__': |
Chad Horohoe | dd22470 | 2018-05-16 22:33:06 -0400 | [diff] [blame] | 47 | unittest.main() |