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