3 # Copyright (c) 2018 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
11 """Define the classes required to fully cover k8s."""
18 from xtesting.core import testcase
20 from functest_kubernetes import k8stest
23 class E2EUnitTesting(unittest.TestCase):
25 # pylint: disable=missing-docstring
28 os.environ["DEPLOY_SCENARIO"] = "k8-test"
29 os.environ["KUBE_MASTER_IP"] = "127.0.0.1"
30 os.environ["KUBE_MASTER_URL"] = "https://127.0.0.1:6443"
31 os.environ["KUBERNETES_PROVIDER"] = "local"
33 self.k8stesting = k8stest.E2ETesting()
35 @mock.patch('os.path.exists', return_value=False)
36 @mock.patch('os.makedirs')
37 @mock.patch('functest_kubernetes.k8stest.os.path.isfile',
39 def test_run_missing_config_file(self, *args):
40 self.k8stesting.config = 'not_file'
41 with mock.patch.object(self.k8stesting,
42 '_E2ETesting__logger') as mock_logger:
43 self.assertEqual(self.k8stesting.run(),
44 testcase.TestCase.EX_RUN_ERROR)
45 mock_logger.error.assert_called_with(
46 "Cannot run k8s testcases. Config file not found")
47 args[0].assert_called_with('not_file')
48 args[1].assert_called_with(self.k8stesting.res_dir)
50 @mock.patch('os.path.exists', return_value=False)
51 @mock.patch('os.makedirs')
52 @mock.patch('re.search')
53 @mock.patch('six.moves.builtins.open', mock.mock_open())
54 @mock.patch('functest_kubernetes.k8stest.os.path.isfile')
55 @mock.patch('functest_kubernetes.k8stest.subprocess.Popen')
56 def test_run(self, *args):
57 self.assertEqual(self.k8stesting.run(),
58 testcase.TestCase.EX_OK)
60 args[loop].assert_called()
63 if __name__ == "__main__":
64 logging.disable(logging.CRITICAL)
65 unittest.main(verbosity=2)