-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat(cli): add validate subcommand #165
Conversation
src/config/mod.rs
Outdated
pub extensions: ExtensionsConfig, | ||
// TODO: #[garde(custom(has_matched_extensions(&self.extensions)))] |
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.
what is this TODO for?
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.
It's for question 1 which I raised at the beginning of this PR's main comments.
src/config/mod.rs
Outdated
} | ||
|
||
#[tokio::test] | ||
#[ignore = "This test is not support yet"] |
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.
why it is not yet supported?
if it is not yet implemented, then no need to have a not working test here
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.
Oh, this is also related to Question 1 in this PR's main comment. If the question gets clarified, I will fix it.
assert!(test_fn(&invalid_params, &()).is_err()); | ||
// since test_fn is FnOnce, we need get a new one | ||
let test_fn = validate_params_with_name(method_name); | ||
assert!(test_fn(&another_invalid_params, &()).is_err()); |
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.
best to break this into two different tests. and need a test for a valid one
Middleware depends on extensions and yes it will be helpful to ensure the required extensions are defined. |
bf9a7bf
to
200e86f
Compare
src/config/mod.rs
Outdated
}; | ||
} | ||
|
||
define_middleware_extension_mappings! { |
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.
this isn't very extensible as we need to define all the mapping here and it is very easy to make mistake when we introduce new extensions or make modifications.
should add a new validate
method to the extension and call it instead. in that way the validation and use are in a same file and harder to modify one without modify others. and we should be able to do it in such way to ensure it is not possible to require an extension without validate it.
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.
Yeah, I agree. As you said, to make it not possible to use without validating it, I think the best way is to ensure it via type-safety. The process is like this: first we validate at some entrypoint which typically in the very beginning, then we wrap it into a new-type, and use this validated new-type all over the rest. Everywhere we use the new-type, we know the value has been validated. But it may take lots of changes in the codes, I will try to get a workaround.
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.
let's remove this part for now so it is not blocking this PR and then we can do the extension validation in next PR
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.
All right.
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.
can you move testing config files into another directory?
Yeah, I felt like doing so. Should I move the |
Resolve #55
Usage:
subway --config configs/config.yml validate
Note: since using
subway validate --config configs/config.yml
mentioned in #55 will require config being the option of thevalidate
subcommand, I use the above form instead. If the former form is proper, a newrun
subcommand can be added.Detailed validations performed
garde
crate's proc_macro to make validation more extendible. Including:endpoint
s must be websocket URL formatmethod
has only one param with inject=truemethod
has only one param with inject=trueendpoint
s connection check, just test if TCP handshake is a successExample Success Output (with exit code 0):
Example Failure Output (with exit code 1):
Questions: