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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 from ansible.plugins.filter.core import regex_search
20 class LocalstorageTest(unittest.TestCase):
23 env = jinja2.Environment(
24 loader=jinja2.FileSystemLoader('./role/templates')
26 env.filters['search'] = regex_search
27 env.tests['search'] = regex_search
28 self.template = env.get_template('localstorage.j2')
30 def ordered(self, obj):
31 if isinstance(obj, dict):
32 return sorted((k, self.ordered(v)) for k, v in obj.items())
33 if isinstance(obj, list):
34 return sorted(self.ordered(x) for x in obj)
37 def verify(self, usecase):
38 with open('./tests/inputs/%s.json' % usecase) as data:
39 inventory = json.load(data)
40 rendered = self.template.render(inventory)
41 actual = json.loads(rendered)
42 with open('./tests/outputs/%s.json' % usecase) as data:
43 expected = json.load(data)
44 self.assertEqual(self.ordered(actual), self.ordered(expected))
46 def test_single_profile(self):
47 self.verify('single_profile')
49 def test_double_profile(self):
50 self.verify('double_profile')
52 def test_triple_profile(self):
53 self.verify('triple_profile')
55 def test_missing_volume(self):
56 self.verify('missing_volume')
58 def test_missing_volume2(self):
59 self.verify('missing_volume2')
61 def test_fewer_partition(self):
62 self.verify('fewer_partition')
64 def test_multinode_hybrid1(self):
65 self.verify('multinode_hybrid1')
67 def test_multinode_hybrid2(self):
68 self.verify('multinode_hybrid2')
70 def test_multinode_hybrid3(self):
71 self.verify('multinode_hybrid3')
73 def test_multinode_hybrid4(self):
74 self.verify('multinode_hybrid4')
76 def test_multinode_hybrid5(self):
77 self.verify('multinode_hybrid5')
79 def test_multinode_hybrid6(self):
80 self.verify('multinode_hybrid6')
82 def test_multinode_hybrid7(self):
83 self.verify('multinode_hybrid7')
85 def test_multinode_hybrid8(self):
86 self.verify('multinode_hybrid8')
88 def test_multinode_hybrid9(self):
89 self.verify('multinode_hybrid9')
91 if __name__ == '__main__':