Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zombienet-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
zombienet-sdk
Commits
8cadb38e
Verified
Commit
8cadb38e
authored
1 year ago
by
Loris Moulin
Browse files
Options
Downloads
Patches
Plain Diff
feat: added new helpers to create InMemoryFile for InMemoryFileSystem
parent
c8cadd71
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/support/src/fs/in_memory.rs
+35
-24
35 additions, 24 deletions
crates/support/src/fs/in_memory.rs
with
35 additions
and
24 deletions
crates/support/src/fs/in_memory.rs
+
35
−
24
View file @
8cadb38e
...
...
@@ -13,13 +13,27 @@ pub enum InMemoryFile {
}
impl
InMemoryFile
{
pub
fn
file
(
contents
:
Vec
<
u8
>
)
->
Self
{
pub
fn
file
<
C
>
(
contents
:
C
)
->
Self
where
C
:
AsRef
<
str
>
,
{
Self
::
file_raw
(
contents
.as_ref
())
}
pub
fn
file_raw
<
C
>
(
contents
:
C
)
->
Self
where
C
:
AsRef
<
[
u8
]
>
,
{
Self
::
File
{
mode
:
0o664
,
contents
,
contents
:
contents
.as_ref
()
.to_vec
()
,
}
}
pub
fn
empty
()
->
Self
{
Self
::
file_raw
(
vec!
[])
}
pub
fn
dir
()
->
Self
{
Self
::
Directory
{
mode
:
0o775
}
}
...
...
@@ -141,10 +155,7 @@ impl FileSystem for InMemoryFileSystem {
return
Err
(
anyhow!
(
"file {:?} is a directory"
,
os_path
)
.into
());
}
files
.insert
(
os_path
.to_owned
(),
InMemoryFile
::
file
(
contents
.as_ref
()
.to_vec
()),
);
files
.insert
(
os_path
.to_owned
(),
InMemoryFile
::
file_raw
(
contents
));
Ok
(())
}
...
...
@@ -239,7 +250,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/dir"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
]));
...
...
@@ -294,7 +305,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/path"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
(
OsString
::
from_str
(
"/path/to"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
...
...
@@ -389,7 +400,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/path"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
(
OsString
::
from_str
(
"/path/to"
)
.unwrap
(),
InMemoryFile
::
dir
()),
]));
...
...
@@ -404,7 +415,7 @@ mod tests {
async
fn
read_should_return_the_file_content
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"content"
),
)]));
let
content
=
fs
.read
(
"/myfile"
)
.await
.unwrap
();
...
...
@@ -437,7 +448,7 @@ mod tests {
async
fn
read_to_string_should_return_the_file_content_as_a_string
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"content"
),
)]));
let
content
=
fs
.read_to_string
(
"/myfile"
)
.await
.unwrap
();
...
...
@@ -470,7 +481,7 @@ mod tests {
async
fn
read_to_string_should_return_an_error_if_file_isnt_utf8_encoded
()
{
let
fs
=
InMemoryFileSystem
::
new
(
HashMap
::
from
([(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[
0xC3
,
0x28
]),
InMemoryFile
::
file
_raw
(
vec!
[
0xC3
,
0x28
]),
)]));
let
err
=
fs
.read_to_string
(
"/myfile"
)
.await
.unwrap_err
();
...
...
@@ -506,7 +517,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
...
...
@@ -557,7 +568,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/path"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
(
OsString
::
from_str
(
"/path/to"
)
.unwrap
(),
InMemoryFile
::
dir
()),
]));
...
...
@@ -577,7 +588,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
...
...
@@ -648,7 +659,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/path"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
(
OsString
::
from_str
(
"/path/to"
)
.unwrap
(),
InMemoryFile
::
dir
()),
]));
...
...
@@ -668,7 +679,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
...
...
@@ -686,11 +697,11 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my new file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my new file content"
),
),
(
OsString
::
from_str
(
"/myfilecopy"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
...
...
@@ -732,7 +743,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
(
OsString
::
from_str
(
"/myfilecopy"
)
.unwrap
(),
...
...
@@ -752,7 +763,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
...
...
@@ -769,11 +780,11 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
(
OsString
::
from_str
(
"/mypath"
)
.unwrap
(),
InMemoryFile
::
file
(
vec!
[]
),
InMemoryFile
::
empty
(
),
),
]));
...
...
@@ -789,7 +800,7 @@ mod tests {
(
OsString
::
from_str
(
"/"
)
.unwrap
(),
InMemoryFile
::
dir
()),
(
OsString
::
from_str
(
"/myfile"
)
.unwrap
(),
InMemoryFile
::
file
(
"my file content"
.as_bytes
()
.to_vec
()
),
InMemoryFile
::
file
(
"my file content"
),
),
]));
assert!
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment