From b6399c69048761584824597b9af38f3c9db4a483 Mon Sep 17 00:00:00 2001 From: Shaoquan Chen Date: Tue, 21 Jul 2015 12:18:53 -0600 Subject: [PATCH] Proving JS source files in consistent order In some deployment environment, the JS source files need to be listed in consistent order so that they will have the same cache key value for the compressed JS file. Change-Id: Ib187a85b7a1fca03c0eb78b411cf121017d40890 Closes-Bug: #1476383 --- horizon/test/tests/test_file_discovery.py | 55 ++++++++++++++++++++--- horizon/utils/file_discovery.py | 2 +- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/horizon/test/tests/test_file_discovery.py b/horizon/test/tests/test_file_discovery.py index 86b76c4eb9..e81e10ff0c 100644 --- a/horizon/test/tests/test_file_discovery.py +++ b/horizon/test/tests/test_file_discovery.py @@ -53,6 +53,12 @@ def fake_walk(path): yield root, [], files +def another_fake_walk(path): + for root, files in reversed(test_structure): + if root.startswith(path): + yield root, [], files + + class FinderTests(unittest.TestCase): def setUp(self): self.old_walk = fd.walk @@ -196,13 +202,50 @@ class FinderTests(unittest.TestCase): self.assertEqual(len(test_files), 8) self.assertEqual(len(templates), 2) - self.assertTrue(sources[0].endswith('.module.js')) - self.assertTrue(sources[1].endswith('.module.js')) + self.assertTrue(sources[0].endswith('a.module.js')) + self.assertTrue(sources[1].endswith('b.module.js')) - self.assertTrue(sources[2].endswith('.controller.js')) - self.assertTrue(sources[3].endswith('.directive.js')) - self.assertTrue(sources[4].endswith('.controller.js')) - self.assertTrue(sources[5].endswith('.directive.js')) + self.assertTrue(sources[2].endswith('a.controller.js')) + self.assertTrue(sources[3].endswith('a.directive.js')) + self.assertTrue(sources[4].endswith('b.controller.js')) + self.assertTrue(sources[5].endswith('b.directive.js')) + + self.assertTrue(test_files[0].endswith('.mock.js')) + self.assertTrue(test_files[1].endswith('.mock.js')) + + self.assertTrue(test_files[2].endswith('.spec.js')) + self.assertTrue(test_files[3].endswith('.spec.js')) + self.assertTrue(test_files[4].endswith('.spec.js')) + self.assertTrue(test_files[5].endswith('.spec.js')) + self.assertTrue(test_files[6].endswith('.spec.js')) + self.assertTrue(test_files[7].endswith('.spec.js')) + + self.assertTrue(templates[0].endswith('.html')) + self.assertTrue(templates[1].endswith('.html')) + + # + # populate_horizon_config() + # + def test_populate_horizon_config_consistent_result(self): + fd.walk = another_fake_walk + horizon_config = {} + + fd.populate_horizon_config(horizon_config, base_path) + sources = horizon_config['js_files'] + test_files = horizon_config['js_spec_files'] + templates = horizon_config['external_templates'] + + self.assertEqual(len(sources), 6) + self.assertEqual(len(test_files), 8) + self.assertEqual(len(templates), 2) + + self.assertTrue(sources[0].endswith('a.module.js')) + self.assertTrue(sources[1].endswith('b.module.js')) + + self.assertTrue(sources[2].endswith('a.controller.js')) + self.assertTrue(sources[3].endswith('a.directive.js')) + self.assertTrue(sources[4].endswith('b.controller.js')) + self.assertTrue(sources[5].endswith('b.directive.js')) self.assertTrue(test_files[0].endswith('.mock.js')) self.assertTrue(test_files[1].endswith('.mock.js')) diff --git a/horizon/utils/file_discovery.py b/horizon/utils/file_discovery.py index e16b45d928..128d4dbd24 100644 --- a/horizon/utils/file_discovery.py +++ b/horizon/utils/file_discovery.py @@ -32,7 +32,7 @@ def discover_files(base_path, sub_path='', ext='', trim_base_path=False): file_list.extend([path.join(root, file_name) for file_name in files if file_name.endswith(ext)]) - return file_list + return sorted(file_list) def sort_js_files(js_files):