def test_no_container_registry_login_tools_found(self, which_mock): # ensure none of the tools are found which_mock.side_effect = create_which_side_effect(cmd=None, cmd_path=None) with self.assertRaisesRegex( RuntimeError, r"When attempting to login to container registry \(registry.example.xyz\) " r"could not find one of the expected tools \(buildah, podman, skopeo\) to login with." ): container_registry_login( container_registry_uri='registry.example.xyz', container_registry_username='******', container_registry_password='******')
def test_use_given_command_does_not_exists(self, which_mock, container_command_mock): which_mock.side_effect = create_which_side_effect(cmd=None, cmd_path=None) with self.assertRaisesRegex( RuntimeError, r"When attempting to login to container registry \(registry.example.xyz\) " r"could not find the given expected tool \(fake-podman\) to login with" ): container_registry_login( container_registry_uri='registry.example.xyz', container_registry_username='******', container_registry_password='******', container_command_short_name='fake-podman')
def test_skopeo(self, which_mock, container_command_mock): which_mock.side_effect = create_which_side_effect( cmd='skopeo', cmd_path='/mock/skopeo') container_registry_login(container_registry_uri='registry.example.xyz', container_registry_username='******', container_registry_password='******') container_command_mock.bake.assert_called_once() container_command_mock.bake().login.bake.assert_called_once_with( password_stdin=True, username='******', tls_verify='true') container_command_mock.bake().login.bake().assert_called_once_with( 'registry.example.xyz', _in='nope', _out=Any(IOBase), _err=Any(IOBase), _tee='err')
def test_buildah_login_fail(self, which_mock, container_command_mock): which_mock.side_effect = create_which_side_effect( cmd='buildah', cmd_path='/mock/buildah') with self.assertRaisesRegex( RuntimeError, re.compile( r"Failed to login to container registry \(registry.example.xyz\)" r" with username \(example\):" r".*RAN: buildah login" r".*STDOUT:" r".*mock stdout" r".*STDERR:" r".*mock stderr login error", re.DOTALL)): container_command_mock.bake().login.bake( ).side_effect = sh.ErrorReturnCode('buildah login', b'mock stdout', b'mock stderr login error') container_registry_login( container_registry_uri='registry.example.xyz', container_registry_username='******', container_registry_password='******')
def test_config_auth_param(self, which_mock, container_command_mock): which_mock.side_effect = create_which_side_effect( cmd='buildah', cmd_path='/mock/buildah') container_registry_login( container_registry_uri='registry.example.xyz', container_registry_username='******', container_registry_password='******', containers_config_auth_file='/tmp/test/auth.json') container_command_mock.bake.assert_called_once() container_command_mock.bake().login.bake.assert_called_once_with( password_stdin=True, username='******', tls_verify='true', authfile='/tmp/test/auth.json') container_command_mock.bake().login.bake().assert_called_once_with( 'registry.example.xyz', _in='nope', _out=Any(IOBase), _err=Any(IOBase), _tee='err')