Haibo Huang | 9dcade4 | 2018-08-03 11:52:25 -0700 | [diff] [blame] | 1 | # Copyright (C) 2018 The Android Open Source Project |
| 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 | """Unit tests for external updater.""" |
| 15 | |
| 16 | import unittest |
| 17 | |
| 18 | import github_archive_updater |
| 19 | |
| 20 | |
| 21 | class ExternalUpdaterTest(unittest.TestCase): |
| 22 | """Unit tests for external updater.""" |
Chih-Hung Hsieh | 4f2dd23 | 2020-08-19 18:52:53 -0700 | [diff] [blame] | 23 | |
Haibo Huang | 9dcade4 | 2018-08-03 11:52:25 -0700 | [diff] [blame] | 24 | def test_url_selection(self): |
| 25 | """Tests that GithubArchiveUpdater can choose the right url.""" |
| 26 | prefix = "https://github.com/author/project/" |
| 27 | urls = [ |
| 28 | prefix + "releases/download/ver-1.0/ver-1.0-binary.zip", |
| 29 | prefix + "releases/download/ver-1.0/ver-1.0-binary.tar.gz", |
| 30 | prefix + "releases/download/ver-1.0/ver-1.0-src.zip", |
| 31 | prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz", |
| 32 | prefix + "archive/ver-1.0.zip", |
| 33 | prefix + "archive/ver-1.0.tar.gz", |
| 34 | ] |
| 35 | |
| 36 | previous_url = prefix + "releases/download/ver-0.9/ver-0.9-src.tar.gz" |
| 37 | url = github_archive_updater.choose_best_url(urls, previous_url) |
| 38 | expected_url = prefix + "releases/download/ver-1.0/ver-1.0-src.tar.gz" |
| 39 | self.assertEqual(url, expected_url) |
| 40 | |
| 41 | previous_url = prefix + "archive/ver-0.9.zip" |
| 42 | url = github_archive_updater.choose_best_url(urls, previous_url) |
| 43 | expected_url = prefix + "archive/ver-1.0.zip" |
| 44 | self.assertEqual(url, expected_url) |
| 45 | |
Chih-Hung Hsieh | 4f2dd23 | 2020-08-19 18:52:53 -0700 | [diff] [blame] | 46 | |
| 47 | if __name__ == "__main__": |
Chih-Hung Hsieh | aa48555 | 2020-08-20 15:45:09 -0700 | [diff] [blame] | 48 | unittest.main(verbosity=2) |