Skip to content
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

refactor tests #157

Merged
merged 5 commits into from
Nov 27, 2020
Merged

refactor tests #157

merged 5 commits into from
Nov 27, 2020

Conversation

jbr
Copy link
Member

@jbr jbr commented Nov 24, 2020

this eliminates the file based TestCase and instead provides strings for locality of reference — it's a lot easier to understand what the test is doing if the request or response content is right in the test. this also splits tests out into client/server x encode/decode

Copy link
Member

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall much better, a few comments

use pretty_assertions::assert_eq;

async fn decode_str(s: &'static str) -> http_types::Result<http_types::Response> {
client::decode(Cursor::new(s.replace("\n", "\r\n"))).await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be easier to read these raw strings if they are e.g.

vec![
    "HTTP/1.1 200 OK",
    "transfer-encoding: chunked",
    "content-type: text/plain",
    "",
    "",
];

with some kind of map(|s| s.append("\r\n") and then a join("").

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, better, although the trailing linebreaks (and any special white space) may become less clear?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't sure about this, but i think it ended up an improvement, which strikes me as a language issue: 59caa84

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are really good! -- Added a few comments, but overall 💯

@@ -0,0 +1,67 @@
mod client_decode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need a surrounding mod; it wraps tests out of the box already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshuawuyts I know these aren't necessary but I like that I can type cargo test client_decode

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(without the extra mod client_decode { line, it doesn't seem work to type cargo test client_decode)

@@ -0,0 +1,178 @@
mod client_encode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need a surrounding mod; it wraps tests out of the box already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, this isn't for rustc, it's so i can type cargo test client_encode and run all of the tests in this module

@@ -0,0 +1,127 @@
mod server_decode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need a surrounding mod; it wraps tests out of the box already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned above, this for convenience of running just one set of tests — I use these like describe in other testing frameworks

@@ -0,0 +1,167 @@
mod server_encode {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need a surrounding mod; it wraps tests out of the box already.

@jbr jbr merged commit 3cbf6ea into main Nov 27, 2020
@delete-merged-branch delete-merged-branch bot deleted the testing branch November 27, 2020 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants