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('functest_kubernetes.k8stest.os.path.isfile',
37 def test_run_missing_config_file(self, mock_func):
38 self.k8stesting.config = 'not_file'
39 with mock.patch.object(self.k8stesting,
40 '_E2ETesting__logger') as mock_logger:
41 self.assertEqual(self.k8stesting.run(),
42 testcase.TestCase.EX_RUN_ERROR)
43 mock_logger.error.assert_called_with(
44 "Cannot run k8s testcases. Config file not found")
45 mock_func.assert_called_with('not_file')
47 @mock.patch('re.search')
48 @mock.patch('six.moves.builtins.open', mock.mock_open())
49 @mock.patch('functest_kubernetes.k8stest.os.path.isfile')
50 @mock.patch('functest_kubernetes.k8stest.subprocess.Popen')
51 def test_run(self, *args):
52 self.assertEqual(self.k8stesting.run(),
53 testcase.TestCase.EX_OK)
55 args[loop].assert_called()
58 if __name__ == "__main__":
59 logging.disable(logging.CRITICAL)
60 unittest.main(verbosity=2)