Exemplo n.º 1
0
    def test_config_file_path_not_specified(self, mock_sys_error,
                                            mock_print_usage, mock_argparse):
        """Test main() with no config_file_path specified."""
        expected_exit_code = 2
        mock_argparse.return_value = NameSpace(endpoint='[::]:50051',
                                               services=['scanner'],
                                               forseti_db=None,
                                               config_file_path=None,
                                               log_level='info',
                                               enable_console_log=False)
        mock_print_usage.return_value = None

        with self.assertRaises(SystemExit) as e:
            server.main()
        self.assertEqual(expected_exit_code, e.exception.code)
        self.assertTrue(mock_sys_error.write.called)
Exemplo n.º 2
0
    def test_config_file_path_non_existent_file(self, mock_sys_error,
                                                mock_print_usage,
                                                mock_argparse):
        """Test main() with non-existent config file."""
        expected_exit_code = 4
        mock_argparse.return_value = NameSpace(endpoint='[::]:50051',
                                               services=['scanner'],
                                               forseti_db=None,
                                               config_file_path='/what/ever',
                                               log_level='info',
                                               enable_console_log=False)
        mock_print_usage.return_value = None

        with mock.patch.object(server.os.path, "isfile") as mock_isfile:
            mock_isfile.return_value = True
            with mock.patch.object(server.os, "access") as mock_access:
                mock_access.return_value = False
                with self.assertRaises(SystemExit) as e:
                    server.main()
        self.assertEqual(expected_exit_code, e.exception.code)
        self.assertTrue(mock_sys_error.write.called)
Exemplo n.º 3
0
def RunForsetiServer():
    """Run Forseti API server."""
    import google.cloud.forseti.services.server as forseti_server
    forseti_server.main()