示例#1
0
    def test_copy_file_to_worker(self):
        """Test file_impl.copy_file_to_worker."""
        request_iterator = (
            untrusted_runner_pb2.FileChunk(data='A'),
            untrusted_runner_pb2.FileChunk(data='B'),
            untrusted_runner_pb2.FileChunk(data='C'),
        )

        context = mock.MagicMock()
        context.invocation_metadata.return_value = (('path-bin', '/file'), )

        response = file_impl.copy_file_to_worker(request_iterator, context)
        self.assertTrue(response.result)
        self.assertTrue(os.path.exists('/file'))
        with open('/file') as f:
            self.assertEqual('ABC', f.read())
示例#2
0
  def test_copy_file_to_worker_create_dir_is_a_file(self):
    """Test file_impl.copy_file_to_worker when the directory is an existing
    file."""
    request_iterator = (
        untrusted_runner_pb2.FileChunk(data=b'A'),
        untrusted_runner_pb2.FileChunk(data=b'B'),
        untrusted_runner_pb2.FileChunk(data=b'C'),
    )

    self.fs.create_file('/file')

    context = mock.MagicMock()
    context.invocation_metadata.return_value = (('path-bin', b'/file/file'),)

    response = file_impl.copy_file_to_worker(request_iterator, context)
    self.assertFalse(response.result)
    self.assertTrue(os.path.isfile('/file'))
示例#3
0
    def test_copy_file_to_worker_create_dir_error(self):
        """Test file_impl.copy_file_to_worker when we fail to create intermediate
    dirs."""
        request_iterator = (
            untrusted_runner_pb2.FileChunk(data='A'),
            untrusted_runner_pb2.FileChunk(data='B'),
            untrusted_runner_pb2.FileChunk(data='C'),
        )

        self.fs.CreateFile('/file')

        context = mock.MagicMock()
        context.invocation_metadata.return_value = (('path-bin',
                                                     '/file/dir/file'), )

        response = file_impl.copy_file_to_worker(request_iterator, context)
        self.assertFalse(response.result)
        self.assertTrue(os.path.isfile('/file'))