From cd27a11da61d40a641d9cee728f5f8ebeb7636c5 Mon Sep 17 00:00:00 2001 From: Pyrode Date: Sat, 3 May 2025 22:26:15 +0530 Subject: [PATCH] test(yank): Added test cases for bad version & prefixed `v` in version --- tests/testsuite/yank.rs | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/testsuite/yank.rs b/tests/testsuite/yank.rs index 04967a7a3..7b66bc5c0 100644 --- a/tests/testsuite/yank.rs +++ b/tests/testsuite/yank.rs @@ -212,3 +212,73 @@ fn inline_and_explicit_version() { "#]]) .run(); } + +#[cargo_test] +fn bad_version() { + let registry = registry::init(); + setup("foo", "0.0.1"); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("yank foo@bar") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +[YANK] foo@bar +[ERROR] failed to yank from the registry at [ROOTURL]/api + +Caused by: + [37] Couldn't read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/bar/yank) + +"#]]) + .run(); +} + +#[cargo_test] +fn prefixed_v_in_version() { + let registry = registry::init(); + setup("foo", "0.0.1"); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("yank bar@v0.0.1") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr_data(str![[r#" +[UPDATING] crates.io index +[YANK] bar@v0.0.1 +[ERROR] failed to yank from the registry at [ROOTURL]/api + +Caused by: + [37] Couldn't read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/bar/v0.0.1/yank) + +"#]]) + .run(); +}