test: migrate search to snapbox

This commit is contained in:
eth3lbert 2024-06-26 05:49:13 +08:00
parent 7dcf764cbc
commit 089dd68d87
No known key found for this signature in database

View File

@ -1,11 +1,10 @@
//! Tests for the `cargo search` command.
#![allow(deprecated)]
use cargo::util::cache_lock::CacheLockMode;
use cargo_test_support::cargo_process;
use cargo_test_support::paths;
use cargo_test_support::registry::{RegistryBuilder, Response};
use cargo_test_support::str;
use std::collections::HashSet;
const SEARCH_API_RESPONSE: &[u8] = br#"
@ -113,8 +112,8 @@ fn not_update() {
cargo_process("search postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stderr("") // without "Updating ... index"
.with_stdout_data(SEARCH_RESULTS)
.with_stderr_data("") // without "Updating ... index"
.run();
}
@ -124,8 +123,11 @@ fn replace_default() {
cargo_process("search postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stderr_contains("[..]Updating [..] index")
.with_stdout_data(SEARCH_RESULTS)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
"#]])
.run();
}
@ -135,7 +137,7 @@ fn simple() {
cargo_process("search postgres --index")
.arg(registry.index_url().as_str())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}
@ -145,7 +147,7 @@ fn multiple_query_params() {
cargo_process("search postgres sql --index")
.arg(registry.index_url().as_str())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}
@ -155,10 +157,11 @@ fn ignore_quiet() {
cargo_process("search -q postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}
#[allow(deprecated)]
#[cargo_test]
fn colored_results() {
let registry = setup().build();
@ -170,7 +173,13 @@ fn colored_results() {
cargo_process("search --color=always postgres")
.replace_crates_io(registry.index_url())
.with_stdout_contains("[..]\x1b[[..]")
.with_stdout_data(
"\
...
[..]\x1b[[..]
...
",
)
.run();
}
@ -181,7 +190,12 @@ fn auth_required_failure() {
cargo_process("search postgres")
.replace_crates_io(server.index_url())
.with_status(101)
.with_stderr_contains("[ERROR] no token found, please run `cargo login`")
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[ERROR] no token found, please run `cargo login`
or use environment variable CARGO_REGISTRY_TOKEN
"#]])
.run();
}
@ -191,6 +205,6 @@ fn auth_required() {
cargo_process("search postgres")
.replace_crates_io(server.index_url())
.with_stdout_contains(SEARCH_RESULTS)
.with_stdout_data(SEARCH_RESULTS)
.run();
}