def test_corrupt_message_partial_body():
    # no trailing newline
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x06hello"))
    # trailing newline bad length
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x07hello\n"))
예제 #2
0
 def decoded_start_result_stdout(self: "Exec") -> List[str]:
     assert self.start_result is not None
     return list(
         docker_log_reader.iter_lines(
             docker_log_reader.iter_messages(self.start_result),
             output_stream=docker_log_reader.DockerLogStream.STDOUT,
         ))
def test_two_small_messages_parsed_correctly():
    assert tuple(
        m.iter_messages(
            b"\x01\x00\x00\x00\x00\x00\x00\x06hello\n"
            b"\x02\x00\x00\x00\x00\x00\x00\x06world\n"
        )
    ) == (
        (m.DockerLogStream.STDOUT, b"hello\n"),
        (m.DockerLogStream.STDERR, b"world\n"),
    )
def test_empty_message_skipped():
    assert tuple(m.iter_messages(b"")) == ()
def test_message_read_failure():
    # expected message length 5 from header does not match line length 4
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x05"))
def test_corrupt_message_missing_body():
    # no body
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x05"))
def test_corrupt_prefix_in_middle():
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"Hi!\x01\x00\x00\x00"))
def test_unrecognized_stream_byte():
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x03\x00\x00\x00\x00\x00\x00\x01"))
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"\x03\x00\x00\x00\x00\x00\x00\x01\n"))
def test_too_short_for_prefix():
    with pytest.raises(m.DockerLogReadError):
        next(m.iter_messages(b"123"))
def test_messages_combined_to_one_line(long_cargo_metadata_output):
    assert len(tuple(m.iter_lines(m.iter_messages(long_cargo_metadata_output)))) == 1
def test_messages_handles_one_long_line_over_many_messages(long_cargo_metadata_output):
    assert len(tuple(m.iter_messages(long_cargo_metadata_output))) == math.ceil(
        len(long_cargo_metadata_output) / m.STARTING_BUF_CONTENTS_LEN
    )
def test_message_containing_newline():
    assert next(
        m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x0eCargo.lock\nfoo")
    ) == (m.DockerLogStream.STDOUT, b"Cargo.lock\nfoo")
def test_small_message():
    assert next(m.iter_messages(b"\x01\x00\x00\x00\x00\x00\x00\x0bCargo.lock\n")) == (
        m.DockerLogStream.STDOUT,
        b"Cargo.lock\n",
    )