Skip to content

Commit

Permalink
test: Add basic fsreplace1 test case
Browse files Browse the repository at this point in the history
This covers the two happy paths of creating a new file and updating an
existing one.
  • Loading branch information
martinpitt committed Feb 13, 2024
1 parent 0f02d6a commit 643dc12
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/pytest/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,45 @@ async def test_fslist1_notexist(transport: MockTransport) -> None:
reply_keys={'message': "[Errno 2] No such file or directory: '/nonexisting'"})


@pytest.mark.asyncio
async def test_fsreplace1(transport: MockTransport, tmp_path: Path) -> None:
# create non-existing file
myfile = tmp_path / 'newfile'
ch = await transport.check_open('fsreplace1', path=str(myfile))
transport.send_data(ch, b'some stuff')
transport.send_done(ch)
await transport.assert_msg('', command='done', channel=ch)
await transport.check_close(channel=ch)
assert myfile.read_bytes() == b'some stuff'
# no leftover files
assert os.listdir(tmp_path) == ['newfile']

# now update its contents
ch = await transport.check_open('fsreplace1', path=str(myfile))
transport.send_data(ch, b'new new new!')
transport.send_done(ch)
await transport.assert_msg('', command='done', channel=ch)
await transport.check_close(channel=ch)
assert myfile.read_bytes() == b'new new new!'
# no leftover files
assert os.listdir(tmp_path) == ['newfile']

# write empty file
ch = await transport.check_open('fsreplace1', path=str(myfile))
transport.send_data(ch, b'')
transport.send_done(ch)
await transport.assert_msg('', command='done', channel=ch)
await transport.check_close(channel=ch)
assert myfile.read_bytes() == b''

# delete file
ch = await transport.check_open('fsreplace1', path=str(myfile))
transport.send_done(ch)
await transport.assert_msg('', command='done', channel=ch)
await transport.check_close(channel=ch)
assert not myfile.exists()


@pytest.mark.asyncio
@pytest.mark.parametrize('channeltype', CHANNEL_TYPES)
async def test_channel(bridge: Bridge, transport: MockTransport, channeltype, tmp_path: Path) -> None:
Expand Down

0 comments on commit 643dc12

Please sign in to comment.