blob: d20641b9ca857f9d78218928688e1199901b71ba [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Dan Willemsen745b4ad2015-10-06 15:23:19 -07002#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import unittest
19
20import wrapper
21
22def fixture(*paths):
23 """Return a path relative to tests/fixtures.
24 """
25 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
26
27class RepoWrapperUnitTest(unittest.TestCase):
28 """Tests helper functions in the repo wrapper
29 """
30 def setUp(self):
31 """Load the wrapper module every time
32 """
33 wrapper._wrapper_module = None
34 self.wrapper = wrapper.Wrapper()
35
36 def test_get_gitc_manifest_dir_no_gitc(self):
37 """
38 Test reading a missing gitc config file
39 """
40 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
41 val = self.wrapper.get_gitc_manifest_dir()
42 self.assertEqual(val, '')
43
44 def test_get_gitc_manifest_dir(self):
45 """
46 Test reading the gitc config file and parsing the directory
47 """
48 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
49 val = self.wrapper.get_gitc_manifest_dir()
50 self.assertEqual(val, '/test/usr/local/google/gitc')
51
52 def test_gitc_parse_clientdir_no_gitc(self):
53 """
54 Test parsing the gitc clientdir without gitc running
55 """
56 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
57 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
58 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
59
60 def test_gitc_parse_clientdir(self):
61 """
62 Test parsing the gitc clientdir
63 """
64 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
65 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
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/'), 'test')
68 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), '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/'), 'test')
71 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
72 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
73 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
74
75if __name__ == '__main__':
76 unittest.main()