e60b6ca7b6e00b4a1de539c4b4e2bc78bc01c921
[sdc/sdc-distribution-client.git] /
1 # Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # 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, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from __future__ import print_function
17
18 import os
19
20 import fixtures
21
22 from pbr.hooks import files
23 from pbr.tests import base
24
25
26 class FilesConfigTest(base.BaseTestCase):
27
28     def setUp(self):
29         super(FilesConfigTest, self).setUp()
30
31         pkg_fixture = fixtures.PythonPackage(
32             "fake_package", [
33                 ("fake_module.py", b""),
34                 ("other_fake_module.py", b""),
35             ])
36         self.useFixture(pkg_fixture)
37         pkg_etc = os.path.join(pkg_fixture.base, 'etc')
38         pkg_sub = os.path.join(pkg_etc, 'sub')
39         subpackage = os.path.join(
40             pkg_fixture.base, 'fake_package', 'subpackage')
41         os.makedirs(pkg_sub)
42         os.makedirs(subpackage)
43         with open(os.path.join(pkg_etc, "foo"), 'w') as foo_file:
44             foo_file.write("Foo Data")
45         with open(os.path.join(pkg_sub, "bar"), 'w') as foo_file:
46             foo_file.write("Bar Data")
47         with open(os.path.join(subpackage, "__init__.py"), 'w') as foo_file:
48             foo_file.write("# empty")
49
50         self.useFixture(base.DiveDir(pkg_fixture.base))
51
52     def test_implicit_auto_package(self):
53         config = dict(
54             files=dict(
55             )
56         )
57         files.FilesConfig(config, 'fake_package').run()
58         self.assertIn('subpackage', config['files']['packages'])
59
60     def test_auto_package(self):
61         config = dict(
62             files=dict(
63                 packages='fake_package',
64             )
65         )
66         files.FilesConfig(config, 'fake_package').run()
67         self.assertIn('subpackage', config['files']['packages'])
68
69     def test_data_files_globbing(self):
70         config = dict(
71             files=dict(
72                 data_files="\n  etc/pbr = etc/*"
73             )
74         )
75         files.FilesConfig(config, 'fake_package').run()
76         self.assertIn(
77             '\netc/pbr/ = \n etc/foo\netc/pbr/sub = \n etc/sub/bar',
78             config['files']['data_files'])