blob: 38def51201d2c6f73917a75fd15a52e069888bfb [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
Mike Frysinger87deaef2019-07-26 21:14:55 -040017"""Unittests for the wrapper.py module."""
18
19from __future__ import print_function
20
Dan Willemsen745b4ad2015-10-06 15:23:19 -070021import os
22import unittest
23
24import wrapper
25
David Pursehouse819827a2020-02-12 15:20:19 +090026
Dan Willemsen745b4ad2015-10-06 15:23:19 -070027def fixture(*paths):
28 """Return a path relative to tests/fixtures.
29 """
30 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
31
David Pursehouse819827a2020-02-12 15:20:19 +090032
Dan Willemsen745b4ad2015-10-06 15:23:19 -070033class RepoWrapperUnitTest(unittest.TestCase):
34 """Tests helper functions in the repo wrapper
35 """
David Pursehouse819827a2020-02-12 15:20:19 +090036
Dan Willemsen745b4ad2015-10-06 15:23:19 -070037 def setUp(self):
38 """Load the wrapper module every time
39 """
40 wrapper._wrapper_module = None
41 self.wrapper = wrapper.Wrapper()
42
43 def test_get_gitc_manifest_dir_no_gitc(self):
44 """
45 Test reading a missing gitc config file
46 """
47 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
48 val = self.wrapper.get_gitc_manifest_dir()
49 self.assertEqual(val, '')
50
51 def test_get_gitc_manifest_dir(self):
52 """
53 Test reading the gitc config file and parsing the directory
54 """
55 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
56 val = self.wrapper.get_gitc_manifest_dir()
57 self.assertEqual(val, '/test/usr/local/google/gitc')
58
59 def test_gitc_parse_clientdir_no_gitc(self):
60 """
61 Test parsing the gitc clientdir without gitc running
62 """
63 self.wrapper.GITC_CONFIG_FILE = fixture('missing_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
67 def test_gitc_parse_clientdir(self):
68 """
69 Test parsing the gitc clientdir
70 """
71 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
72 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
73 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
74 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
75 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
76 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
77 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
78 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
79 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
80 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
81
David Pursehouse819827a2020-02-12 15:20:19 +090082
Dan Willemsen745b4ad2015-10-06 15:23:19 -070083if __name__ == '__main__':
84 unittest.main()