blob: fb32e38a13290254b1e95ba90ddc377f3caef162 [file] [log] [blame]
Dan Willemsen745b4ad2015-10-06 15:23:19 -07001#
2# Copyright (C) 2015 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
16import os
17import unittest
18
19import wrapper
20
21def fixture(*paths):
22 """Return a path relative to tests/fixtures.
23 """
24 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
25
26class RepoWrapperUnitTest(unittest.TestCase):
27 """Tests helper functions in the repo wrapper
28 """
29 def setUp(self):
30 """Load the wrapper module every time
31 """
32 wrapper._wrapper_module = None
33 self.wrapper = wrapper.Wrapper()
34
35 def test_get_gitc_manifest_dir_no_gitc(self):
36 """
37 Test reading a missing gitc config file
38 """
39 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
40 val = self.wrapper.get_gitc_manifest_dir()
41 self.assertEqual(val, '')
42
43 def test_get_gitc_manifest_dir(self):
44 """
45 Test reading the gitc config file and parsing the directory
46 """
47 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
48 val = self.wrapper.get_gitc_manifest_dir()
49 self.assertEqual(val, '/test/usr/local/google/gitc')
50
51 def test_gitc_parse_clientdir_no_gitc(self):
52 """
53 Test parsing the gitc clientdir without gitc running
54 """
55 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
56 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
57 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
58
59 def test_gitc_parse_clientdir(self):
60 """
61 Test parsing the gitc clientdir
62 """
63 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
64 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
65 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
66 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
67 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
68 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
69 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
70 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
71 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
72 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
73
74if __name__ == '__main__':
75 unittest.main()