From c2946d933c22cd171e40166cf28519212ddb9ce0 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 27 Sep 2023 14:28:18 +0200 Subject: [PATCH] tests/krate/publish/keywords: Replace hardcoded error message expectations with insta snapshots (#7196) --- src/tests/krate/publish/keywords.rs | 15 +++------------ ..._krate__publish__keywords__bad_keywords-2.snap | 11 +++++++++++ ..._krate__publish__keywords__bad_keywords-3.snap | 11 +++++++++++ ...l__krate__publish__keywords__bad_keywords.snap | 11 +++++++++++ 4 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-2.snap create mode 100644 src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-3.snap create mode 100644 src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords.snap diff --git a/src/tests/krate/publish/keywords.rs b/src/tests/krate/publish/keywords.rs index e85544dbb23..7313f8269d7 100644 --- a/src/tests/krate/publish/keywords.rs +++ b/src/tests/krate/publish/keywords.rs @@ -22,26 +22,17 @@ fn bad_keywords() { PublishBuilder::new("foo_bad_key", "1.0.0").keyword("super-long-keyword-name-oh-no"); let response = token.publish_crate(crate_to_publish); assert_eq!(response.status(), StatusCode::OK); - assert_eq!( - 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" }] }) - ); + assert_json_snapshot!(response.into_json()); let crate_to_publish = PublishBuilder::new("foo_bad_key", "1.0.0").keyword("?@?%"); let response = token.publish_crate(crate_to_publish); assert_eq!(response.status(), StatusCode::OK); - assert_eq!( - response.into_json(), - json!({ "errors": [{ "detail": "invalid upload request: invalid value: string \"?@?%\", expected a valid keyword specifier at line 1 column 178" }] }) - ); + assert_json_snapshot!(response.into_json()); let crate_to_publish = PublishBuilder::new("foo_bad_key", "1.0.0").keyword("áccênts"); let response = token.publish_crate(crate_to_publish); assert_eq!(response.status(), StatusCode::OK); - assert_eq!( - response.into_json(), - json!({ "errors": [{ "detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 183" }] }) - ); + assert_json_snapshot!(response.into_json()); } #[test] diff --git a/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-2.snap b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-2.snap new file mode 100644 index 00000000000..d72df4ab2c3 --- /dev/null +++ b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-2.snap @@ -0,0 +1,11 @@ +--- +source: src/tests/krate/publish/keywords.rs +expression: response.into_json() +--- +{ + "errors": [ + { + "detail": "invalid upload request: invalid value: string \"?@?%\", expected a valid keyword specifier at line 1 column 178" + } + ] +} diff --git a/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-3.snap b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-3.snap new file mode 100644 index 00000000000..87a68ab7391 --- /dev/null +++ b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords-3.snap @@ -0,0 +1,11 @@ +--- +source: src/tests/krate/publish/keywords.rs +expression: response.into_json() +--- +{ + "errors": [ + { + "detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 183" + } + ] +} diff --git a/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords.snap b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords.snap new file mode 100644 index 00000000000..00eb6ecb4ec --- /dev/null +++ b/src/tests/krate/publish/snapshots/all__krate__publish__keywords__bad_keywords.snap @@ -0,0 +1,11 @@ +--- +source: src/tests/krate/publish/keywords.rs +expression: response.into_json() +--- +{ + "errors": [ + { + "detail": "invalid upload request: invalid length 29, expected a keyword with less than 20 characters at line 1 column 203" + } + ] +}