-
Notifications
You must be signed in to change notification settings - Fork 2
test: add tests for files being created and modified with text editors #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM quay.io/fedora/fedora:43 | ||
|
|
||
| RUN dnf install -y \ | ||
| neovim \ | ||
| vim |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import os | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def get_vi_test_file(dir): | ||
| return os.path.join(dir, '4913') | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session') | ||
| def build_editor_image(docker_client): | ||
| image, _ = docker_client.images.build( | ||
| path='containers/editors', | ||
| tag='editors:latest', | ||
| dockerfile='Containerfile', | ||
| ) | ||
| return image | ||
|
|
||
|
|
||
| def run_editor_container(image, docker_client, ignored_dir): | ||
| container = docker_client.containers.run( | ||
| image, | ||
| detach=True, | ||
| tty=True, | ||
| name='editors', | ||
| volumes={ | ||
| ignored_dir: { | ||
| 'bind': '/mounted', | ||
| 'mode': 'z', | ||
| }, | ||
| }, | ||
| ) | ||
| container.exec_run('mkdir /container-dir') | ||
|
|
||
| yield container | ||
|
|
||
| container.kill() | ||
| container.remove() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def vi_container(docker_client, ignored_dir): | ||
| yield from run_editor_container('quay.io/fedora/fedora:43', docker_client, ignored_dir) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def editor_container(build_editor_image, docker_client, ignored_dir): | ||
| image = build_editor_image.tags[0] | ||
| yield from run_editor_container(image, docker_client, ignored_dir) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| from event import Event, EventType, Process | ||
|
|
||
| from test_editors.commons import get_vi_test_file | ||
|
|
||
|
|
||
| def test_new_file(editor_container, server): | ||
| fut = '/mounted/test.txt' | ||
|
|
||
| editor_container.exec_run( | ||
| f"nvim {fut} +':normal iThis is a test<CR>' -c x") | ||
|
|
||
| process = Process.in_container( | ||
| exe_path='/usr/bin/nvim', | ||
| args=f'nvim {fut} +:normal iThis is a test<CR> -c x', | ||
| name='nvim', | ||
| container_id=editor_container.id[:12], | ||
| ) | ||
| events = [ | ||
| Event(process=process, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| ] | ||
|
|
||
| for e in events: | ||
| print(f'Waiting for event: {e}') | ||
|
|
||
| server.wait_events(events, strict=True) | ||
|
|
||
|
|
||
| def test_open_file(editor_container, server): | ||
| fut = '/mounted/test.txt' | ||
| container_id = editor_container.id[:12] | ||
|
|
||
| # We ensure the file exists before editing. | ||
| editor_container.exec_run(f'touch {fut}') | ||
| editor_container.exec_run( | ||
| f"nvim {fut} +':normal iThis is a test<CR>' -c x") | ||
|
|
||
| touch = Process.in_container( | ||
| exe_path='/usr/bin/touch', | ||
| args=f'touch {fut}', | ||
| name='touch', | ||
| container_id=container_id, | ||
| ) | ||
| nvim = Process.in_container( | ||
| exe_path='/usr/bin/nvim', | ||
| args=f'nvim {fut} +:normal iThis is a test<CR> -c x', | ||
| name='nvim', | ||
| container_id=container_id, | ||
| ) | ||
|
|
||
| vi_test_file = get_vi_test_file('/mounted') | ||
|
|
||
| events = [ | ||
| Event(process=touch, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| Event(process=nvim, event_type=EventType.CREATION, | ||
| file=vi_test_file, host_path=''), | ||
| Event(process=nvim, event_type=EventType.OWNERSHIP, | ||
| file=vi_test_file, host_path='', owner_uid=0, owner_gid=0), | ||
| Event(process=nvim, event_type=EventType.UNLINK, | ||
| file=vi_test_file, host_path=''), | ||
| Event(process=nvim, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| Event(process=nvim, event_type=EventType.PERMISSION, | ||
| file=fut, host_path='', mode=0o100644), | ||
| Event(process=nvim, event_type=EventType.UNLINK, | ||
| file=f'{fut}~', host_path=''), | ||
| ] | ||
|
|
||
| for e in events: | ||
| print(f'Waiting for event: {e}') | ||
|
|
||
| server.wait_events(events, strict=True) | ||
|
|
||
|
|
||
| def test_new_file_ovfs(editor_container, server): | ||
| fut = '/container-dir/test.txt' | ||
|
|
||
| editor_container.exec_run( | ||
| f"nvim {fut} +':normal iThis is a test<CR>' -c x") | ||
|
|
||
| process = Process.in_container( | ||
| exe_path='/usr/bin/nvim', | ||
| args=f'nvim {fut} +:normal iThis is a test<CR> -c x', | ||
| name='nvim', | ||
| container_id=editor_container.id[:12], | ||
| ) | ||
| events = [ | ||
| Event(process=process, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| Event(process=process, event_type=EventType.OPEN, | ||
| file=fut, host_path=''), | ||
| ] | ||
|
|
||
| for e in events: | ||
| print(f'Waiting for event: {e}') | ||
|
|
||
| server.wait_events(events, strict=True) | ||
|
|
||
|
|
||
| def test_open_file_ovfs(editor_container, server): | ||
| fut = '/container-dir/test.txt' | ||
| container_id = editor_container.id[:12] | ||
|
|
||
| # We ensure the file exists before editing. | ||
| editor_container.exec_run(f'touch {fut}') | ||
| editor_container.exec_run( | ||
| f"nvim {fut} +':normal iThis is a test<CR>' -c x") | ||
|
|
||
| touch = Process.in_container( | ||
| exe_path='/usr/bin/touch', | ||
| args=f'touch {fut}', | ||
| name='touch', | ||
| container_id=container_id, | ||
| ) | ||
| nvim = Process.in_container( | ||
| exe_path='/usr/bin/nvim', | ||
| args=f'nvim {fut} +:normal iThis is a test<CR> -c x', | ||
| name='nvim', | ||
| container_id=container_id, | ||
| ) | ||
|
|
||
| vi_test_file = get_vi_test_file('/container-dir') | ||
|
|
||
| events = [ | ||
| Event(process=touch, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| Event(process=touch, event_type=EventType.OPEN, | ||
| file=fut, host_path=''), | ||
| Event(process=nvim, event_type=EventType.CREATION, | ||
| file=vi_test_file, host_path=''), | ||
| Event(process=nvim, event_type=EventType.OPEN, | ||
| file=vi_test_file, host_path=''), | ||
| Event(process=nvim, event_type=EventType.OWNERSHIP, | ||
| file=vi_test_file, host_path='', owner_uid=0, owner_gid=0), | ||
| Event(process=nvim, event_type=EventType.UNLINK, | ||
| file=vi_test_file, host_path=''), | ||
| Event(process=nvim, event_type=EventType.CREATION, | ||
| file=fut, host_path=''), | ||
| Event(process=nvim, event_type=EventType.OPEN, | ||
| file=fut, host_path=''), | ||
| Event(process=nvim, event_type=EventType.PERMISSION, | ||
| file=fut, host_path='', mode=0o100644), | ||
| Event(process=nvim, event_type=EventType.UNLINK, | ||
| file=f'{fut}~', host_path=''), | ||
| ] | ||
|
|
||
| for e in events: | ||
| print(f'Waiting for event: {e}') | ||
|
|
||
| server.wait_events(events, strict=True) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about
yield from. Neat.