Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
candidate 6 applications developer
Arti
Commits
9fdb7d97
Commit
9fdb7d97
authored
3 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
More tests for tor-config.
parent
54de7f5c
No related branches found
Branches containing commit
Tags
tor-0.3.3.4-alpha
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
crates/tor-config/src/err.rs
+54
-0
54 additions, 0 deletions
crates/tor-config/src/err.rs
crates/tor-config/src/path.rs
+17
-2
17 additions, 2 deletions
crates/tor-config/src/path.rs
with
71 additions
and
2 deletions
crates/tor-config/src/err.rs
+
54
−
0
View file @
9fdb7d97
...
...
@@ -57,3 +57,57 @@ impl ConfigBuildError {
}
}
}
#[cfg(test)]
mod
test
{
use
super
::
*
;
#[test]
fn
within
()
{
let
e1
=
ConfigBuildError
::
MissingField
{
field
:
"lettuce"
.to_owned
(),
};
let
e2
=
ConfigBuildError
::
Invalid
{
field
:
"tomato"
.to_owned
(),
problem
:
"too crunchy"
.to_owned
(),
};
let
e3
=
ConfigBuildError
::
Inconsistent
{
fields
:
vec!
[
"mayo"
.to_owned
(),
"avocado"
.to_owned
()],
problem
:
"pick one"
.to_owned
(),
};
assert_eq!
(
&
e1
.within
(
"sandwich"
)
.to_string
(),
"Field was not provided: sandwich.lettuce"
);
assert_eq!
(
&
e2
.within
(
"sandwich"
)
.to_string
(),
"Value of sandwich.tomato was incorrect: too crunchy"
);
assert_eq!
(
&
e3
.within
(
"sandwich"
)
.to_string
(),
r#"Fields ["sandwich.mayo", "sandwich.avocado"] are inconsistent: pick one"#
);
}
#[derive(derive_builder::Builder,
Debug)]
#[builder(build_fn(error
=
"ConfigBuildError"
))]
struct
Cephalopod
{
// arms have suction cups for their whole length
arms
:
u8
,
// Tentacles have suction cups at the ends
tentacles
:
u8
,
}
#[test]
fn
builderr
()
{
let
squid
=
CephalopodBuilder
::
default
()
.arms
(
8
)
.tentacles
(
2
)
.build
();
let
octopus
=
CephalopodBuilder
::
default
()
.arms
(
8
)
.build
();
assert!
(
squid
.is_ok
());
assert!
(
octopus
.is_err
());
assert_eq!
(
&
octopus
.unwrap_err
()
.to_string
(),
"Field was not provided: tentacles"
);
}
}
This diff is collapsed.
Click to expand it.
crates/tor-config/src/path.rs
+
17
−
2
View file @
9fdb7d97
...
...
@@ -130,7 +130,7 @@ fn get_env(var: &str) -> Result<Option<&'static str>, CfgPathError> {
impl
std
::
fmt
::
Display
for
CfgPath
{
fn
fmt
(
&
self
,
fmt
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
match
&
self
.0
{
PathInner
::
Literal
(
p
)
=>
write!
(
fmt
,
"{:?}"
,
p
),
PathInner
::
Literal
(
p
)
=>
write!
(
fmt
,
"{:?}
[exactly]
"
,
p
),
PathInner
::
Shell
(
s
)
=>
s
.fmt
(
fmt
),
}
}
...
...
@@ -200,6 +200,21 @@ mod test {
let
p
=
CfgPath
::
new
(
"${ARTI_WOMBAT}/example"
.to_string
());
assert_eq!
(
p
.to_string
(),
"${ARTI_WOMBAT}/example"
.to_string
());
assert!
(
p
.path
()
.is_err
());
assert!
(
matches!
(
p
.path
(),
Err
(
CfgPathError
::
UnknownVar
(
_
))));
assert_eq!
(
&
p
.path
()
.unwrap_err
()
.to_string
(),
"unrecognized variable ARTI_WOMBAT"
);
}
#[test]
fn
literal
()
{
let
p
=
CfgPath
::
from_path
(
PathBuf
::
from
(
"${ARTI_CACHE}/literally"
));
// This doesn't get expanded, since we're using a literal path.
assert_eq!
(
p
.path
()
.unwrap
()
.to_str
()
.unwrap
(),
"${ARTI_CACHE}/literally"
);
assert_eq!
(
p
.to_string
(),
"
\"
${ARTI_CACHE}/literally
\"
[exactly]"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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