Skip to content

Rename the json method of Response to into_json #3832

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

Merged
merged 1 commit into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tests/account_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn account_locked_indefinitely() {
LOCK_REASON
);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": error_message }] })
);
}
Expand All @@ -55,7 +55,7 @@ fn account_locked_with_future_expiry() {
until, LOCK_REASON,
);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": error_message }] })
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn anonymous_user_unauthorized() {
let response: Response<Body> = anon.get(URL);

assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(response.json().to_string().as_bytes(), MUST_LOGIN);
assert_eq!(response.into_json().to_string().as_bytes(), MUST_LOGIN);
}

#[test]
Expand All @@ -26,7 +26,7 @@ fn token_auth_cannot_find_token() {
let response: Response<Body> = anon.run(request);

assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(response.json().to_string().as_bytes(), MUST_LOGIN);
assert_eq!(response.into_json().to_string().as_bytes(), MUST_LOGIN);
}

// Ensure that an unexpected authentication error is available for logging. The user would see
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn dependencies() {
let response = anon.get::<()>("/api/v1/crates/foo_deps/1.0.2/dependencies");
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "crate `foo_deps` does not have a version `1.0.2`" }] })
);
}
48 changes: 24 additions & 24 deletions src/tests/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn new_wrong_token() {
let response = anon.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "must be logged in to perform that action" }] })
);

Expand All @@ -75,7 +75,7 @@ fn new_wrong_token() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "must be logged in to perform that action" }] })
);
}
Expand All @@ -89,7 +89,7 @@ fn invalid_names() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);

let json = response.json();
let json = response.into_json();
let json = json.as_object().unwrap();
let errors = json.get("errors").unwrap().as_array().unwrap();
let first_error = errors.first().unwrap().as_object().unwrap();
Expand Down Expand Up @@ -281,7 +281,7 @@ fn reject_new_krate_with_non_exact_dependency() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "no known crate named `foo_dep`" }] })
);
}
Expand Down Expand Up @@ -310,7 +310,7 @@ fn reject_new_crate_with_alternative_registry_dependency() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "Dependency `dep` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io." }] })
);
}
Expand All @@ -333,7 +333,7 @@ fn new_krate_with_wildcard_dependency() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": WILDCARD_ERROR_MESSAGE }] })
);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ fn new_krate_wrong_user() {
let response = another_user.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": MISSING_RIGHTS_ERROR_MESSAGE }] })
);
}
Expand All @@ -387,7 +387,7 @@ fn new_krate_too_big() {
let response = user.enqueue_publish(builder);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "uploaded tarball is malformed or too large when decompressed" }] })
);
}
Expand Down Expand Up @@ -420,7 +420,7 @@ fn new_krate_wrong_files() {
let response = user.enqueue_publish(builder);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid tarball uploaded" }] })
);
}
Expand All @@ -439,7 +439,7 @@ fn new_krate_gzip_bomb() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "uploaded tarball is malformed or too large when decompressed" }] })
);
}
Expand All @@ -459,7 +459,7 @@ fn new_krate_duplicate_version() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "crate version `1.0.0` is already uploaded" }] })
);
}
Expand All @@ -478,7 +478,7 @@ fn new_crate_similar_name() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "crate was previously named `Foo_similar`" }] })
);
}
Expand All @@ -497,7 +497,7 @@ fn new_crate_similar_name_hyphen() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "crate was previously named `foo_bar_hyphen`" }] })
);
}
Expand All @@ -516,7 +516,7 @@ fn new_crate_similar_name_underscore() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "crate was previously named `foo-bar-underscore`" }] })
);
}
Expand Down Expand Up @@ -589,7 +589,7 @@ fn new_krate_dependency_missing() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "no known crate named `bar_missing`" }] })
);
}
Expand Down Expand Up @@ -618,7 +618,7 @@ fn new_krate_without_any_email_fails() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "A verified email address is required to publish crates to crates.io. Visit https://crates.io/me to set and verify your email address." }] })
);
}
Expand All @@ -639,7 +639,7 @@ fn new_krate_with_unverified_email_fails() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "A verified email address is required to publish crates to crates.io. Visit https://crates.io/me to set and verify your email address." }] })
);
}
Expand Down Expand Up @@ -729,23 +729,23 @@ fn bad_keywords() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid upload request: invalid length 29, expected a keyword with less than 20 characters at line 1 column 203" }] })
);

let crate_to_publish = PublishBuilder::new("foo_bad_key").keyword("?@?%");
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid upload request: invalid value: string \"?@?%\", expected a valid keyword specifier at line 1 column 178" }] })
);

let crate_to_publish = PublishBuilder::new("foo_bad_key").keyword("áccênts");
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 183" }] })
);
}
Expand Down Expand Up @@ -856,7 +856,7 @@ fn license_and_description_required() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": missing_metadata_error_message(&["description", "license"]) }] })
);

Expand All @@ -867,7 +867,7 @@ fn license_and_description_required() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": missing_metadata_error_message(&["description"]) }] })
);

Expand All @@ -880,7 +880,7 @@ fn license_and_description_required() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": missing_metadata_error_message(&["description"]) }] })
);
}
Expand All @@ -907,7 +907,7 @@ fn new_krate_tarball_with_hard_links() {
let response = token.enqueue_publish(crate_to_publish);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid tarball uploaded" }] })
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/krate/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,15 +807,15 @@ fn pagination_parameters_only_accept_integers() {
anon.get_with_query::<()>("/api/v1/crates", "page=1&per_page=100%22%EF%BC%8Cexception");
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid digit found in string" }] })
);

let response =
anon.get_with_query::<()>("/api/v1/crates", "page=100%22%EF%BC%8Cexception&per_page=1");
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "invalid digit found in string" }] })
);
}
2 changes: 1 addition & 1 deletion src/tests/krate/yanking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn yank_by_a_non_owner_fails() {
let response = token.yank("foo_not", "1.0.0");
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.json(),
response.into_json(),
json!({ "errors": [{ "detail": "must already be an owner to yank or unyank" }] })
);
}
Expand Down
Loading