-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests for the dev files and added urandom support
- Loading branch information
1 parent
d7e2129
commit b9c5d21
Showing
41 changed files
with
310 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,88 @@ | ||
//! Used for /dev/zero - infinitely returns zero | ||
//! which is useful for commands like `dd if=/dev/zero of=bigfile.img size=1G` | ||
use std::io::{self, *}; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite}; | ||
|
||
use crate::VirtualFile; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct RandomFile { } | ||
|
||
impl AsyncSeek for RandomFile { | ||
fn start_seek(self: Pin<&mut Self>, _position: SeekFrom) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
fn poll_complete(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<u64>> { | ||
Poll::Ready(Ok(0)) | ||
} | ||
} | ||
|
||
impl AsyncWrite for RandomFile { | ||
fn poll_write( | ||
self: Pin<&mut Self>, | ||
_cx: &mut Context<'_>, | ||
buf: &[u8], | ||
) -> Poll<io::Result<usize>> { | ||
Poll::Ready(Ok(buf.len())) | ||
} | ||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { | ||
Poll::Ready(Ok(())) | ||
} | ||
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> { | ||
Poll::Ready(Ok(())) | ||
} | ||
fn poll_write_vectored( | ||
self: Pin<&mut Self>, | ||
_cx: &mut Context<'_>, | ||
bufs: &[IoSlice<'_>], | ||
) -> Poll<io::Result<usize>> { | ||
Poll::Ready(Ok(bufs.len())) | ||
} | ||
fn is_write_vectored(&self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
impl AsyncRead for RandomFile { | ||
fn poll_read( | ||
self: Pin<&mut Self>, | ||
_cx: &mut Context<'_>, | ||
buf: &mut tokio::io::ReadBuf<'_>, | ||
) -> Poll<io::Result<()>> { | ||
let mut data = vec! [0u8; buf.remaining()]; | ||
getrandom::getrandom(&mut data).ok(); | ||
buf.put_slice(&data[..]); | ||
Poll::Ready(Ok(())) | ||
} | ||
} | ||
|
||
impl VirtualFile for RandomFile { | ||
fn last_accessed(&self) -> u64 { | ||
0 | ||
} | ||
fn last_modified(&self) -> u64 { | ||
0 | ||
} | ||
fn created_time(&self) -> u64 { | ||
0 | ||
} | ||
fn size(&self) -> u64 { | ||
0 | ||
} | ||
fn set_len(&mut self, _new_size: u64) -> crate::Result<()> { | ||
Ok(()) | ||
} | ||
fn unlink(&mut self) -> crate::Result<()> { | ||
Ok(()) | ||
} | ||
fn poll_read_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> { | ||
Poll::Ready(Ok(0)) | ||
} | ||
fn poll_write_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<usize>> { | ||
Poll::Ready(Ok(0)) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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
58 changes: 58 additions & 0 deletions
58
tests/integration/cli/tests/snapshots/snapshot__snapshot_dash_dev_urandom.snap
This file contains 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,58 @@ | ||
--- | ||
source: tests/integration/cli/tests/snapshot.rs | ||
assertion_line: 642 | ||
expression: snapshot | ||
--- | ||
{ | ||
"spec": { | ||
"name": "snapshot::test_snapshot_dash_dev_urandom", | ||
"use_packages": [ | ||
"sharrattj/coreutils" | ||
], | ||
"cli_args": [], | ||
"stdin": [ | ||
104, | ||
101, | ||
97, | ||
100, | ||
32, | ||
45, | ||
99, | ||
32, | ||
49, | ||
48, | ||
32, | ||
47, | ||
100, | ||
101, | ||
118, | ||
47, | ||
117, | ||
114, | ||
97, | ||
110, | ||
100, | ||
111, | ||
109, | ||
32, | ||
124, | ||
32, | ||
119, | ||
99, | ||
32, | ||
45, | ||
99 | ||
], | ||
"debug_output": false, | ||
"enable_threads": true, | ||
"enable_network": false, | ||
"http_request": null | ||
}, | ||
"result": { | ||
"Success": { | ||
"stdout": "10\n", | ||
"stderr": "# # \n", | ||
"exit_code": 0 | ||
} | ||
} | ||
} |
Oops, something went wrong.