def test_git_credentials_passed_to_podspec_upon_submit(): git_credentials = { 'client_id': 'my_username', 'access_token': 'my_access_token', } build = Build( mock.MagicMock(), api=mock.MagicMock(), name='test_build', namespace='build_namespace', repo_url=mock.MagicMock(), ref=mock.MagicMock(), git_credentials=git_credentials, builder_image=mock.MagicMock(), image_name=mock.MagicMock(), push_secret=mock.MagicMock(), memory_limit=mock.MagicMock(), docker_host='http://mydockerregistry.local', node_selector=mock.MagicMock()) with mock.patch.object(build, 'api') as api_patch, \ mock.patch.object(build.stop_event, 'is_set', return_value=True): build.submit() call_args_list = api_patch.create_namespaced_pod.call_args_list assert len(call_args_list) == 1 args = call_args_list[0][0] pod = args[1] assert len(pod.spec.containers) == 1 env = { env_var.name: env_var.value for env_var in pod.spec.containers[0].env } assert env['GIT_CREDENTIAL_ENV'] == git_credentials
def test_weko3_hosts_passed_to_podspec_upon_submit(): weko3_hosts = [{ 'hostname': ['https://test.jp'], 'file_base_url': 'https://test.jp/api/files', }] optional_envs = {'WEKO3_HOSTS_JSON': json.dumps(weko3_hosts)} mock_k8s_api = _list_dind_pods_mock() build = Build(mock.MagicMock(), api=mock_k8s_api, name='test_build', namespace='build_namespace', repo_url=mock.MagicMock(), ref=mock.MagicMock(), git_credentials=None, optional_envs=optional_envs, build_image=mock.MagicMock(), image_name=mock.MagicMock(), push_secret=mock.MagicMock(), memory_limit=mock.MagicMock(), docker_host='http://mydockerregistry.local', node_selector=mock.MagicMock()) with mock.patch.object(build.stop_event, 'is_set', return_value=True): build.submit() call_args_list = mock_k8s_api.create_namespaced_pod.call_args_list assert len(call_args_list) == 1 args = call_args_list[0][0] pod = args[1] assert len(pod.spec.containers) == 1 env = { env_var.name: env_var.value for env_var in pod.spec.containers[0].env } assert json.loads(env['WEKO3_HOSTS_JSON']) == weko3_hosts
def test_git_credentials_passed_to_podspec_upon_submit(): git_credentials = """{ "client_id": "my_username", "access_token": "my_access_token", }""" mock_k8s_api = _list_dind_pods_mock() build = Build( mock.MagicMock(), api=mock_k8s_api, name="test_build", namespace="build_namespace", repo_url="repo", ref="ref", build_image="image", image_name="name", push_secret="", memory_limit=0, git_credentials=git_credentials, docker_host="http://mydockerregistry.local", node_selector={}, ) with mock.patch.object(build.stop_event, "is_set", return_value=True): build.submit() call_args_list = mock_k8s_api.create_namespaced_pod.call_args_list assert len(call_args_list) == 1 args = call_args_list[0][0] pod = args[1] assert len(pod.spec.containers) == 1 env = { env_var.name: env_var.value for env_var in pod.spec.containers[0].env } assert env["GIT_CREDENTIAL_ENV"] == git_credentials