2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo search` command.
|
|
|
|
|
2023-09-07 04:01:18 +00:00
|
|
|
use cargo::util::cache_lock::CacheLockMode;
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::cargo_process;
|
|
|
|
use cargo_test_support::paths;
|
2022-06-09 03:04:33 +00:00
|
|
|
use cargo_test_support::registry::{RegistryBuilder, Response};
|
2020-04-17 04:10:11 +00:00
|
|
|
use std::collections::HashSet;
|
2014-12-07 20:25:32 +00:00
|
|
|
|
2022-06-09 03:04:33 +00:00
|
|
|
const SEARCH_API_RESPONSE: &[u8] = br#"
|
|
|
|
{
|
|
|
|
"crates": [{
|
|
|
|
"created_at": "2014-11-16T20:17:35Z",
|
|
|
|
"description": "Design by contract style assertions for Rust",
|
|
|
|
"documentation": null,
|
|
|
|
"downloads": 2,
|
|
|
|
"homepage": null,
|
|
|
|
"id": "hoare",
|
|
|
|
"keywords": [],
|
|
|
|
"license": null,
|
|
|
|
"links": {
|
|
|
|
"owners": "/api/v1/crates/hoare/owners",
|
|
|
|
"reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
|
|
|
|
"version_downloads": "/api/v1/crates/hoare/downloads",
|
|
|
|
"versions": "/api/v1/crates/hoare/versions"
|
2020-05-12 15:03:35 +00:00
|
|
|
},
|
2022-06-09 03:04:33 +00:00
|
|
|
"max_version": "0.1.1",
|
|
|
|
"name": "hoare",
|
|
|
|
"repository": "https://github.com/nick29581/libhoare",
|
|
|
|
"updated_at": "2014-11-20T21:49:21Z",
|
|
|
|
"versions": null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": "postgres",
|
|
|
|
"name": "postgres",
|
|
|
|
"updated_at": "2020-05-01T23:17:54.335921+00:00",
|
|
|
|
"versions": null,
|
|
|
|
"keywords": null,
|
|
|
|
"categories": null,
|
|
|
|
"badges": [
|
|
|
|
{
|
|
|
|
"badge_type": "circle-ci",
|
|
|
|
"attributes": {
|
|
|
|
"repository": "sfackler/rust-postgres",
|
|
|
|
"branch": null
|
2020-05-12 15:03:35 +00:00
|
|
|
}
|
2022-06-09 03:04:33 +00:00
|
|
|
}
|
2020-05-12 15:03:35 +00:00
|
|
|
],
|
2022-06-09 03:04:33 +00:00
|
|
|
"created_at": "2014-11-24T02:34:44.756689+00:00",
|
|
|
|
"downloads": 535491,
|
|
|
|
"recent_downloads": 88321,
|
|
|
|
"max_version": "0.17.3",
|
|
|
|
"newest_version": "0.17.3",
|
|
|
|
"description": "A native, synchronous PostgreSQL client",
|
|
|
|
"homepage": null,
|
|
|
|
"documentation": null,
|
|
|
|
"repository": "https://github.com/sfackler/rust-postgres",
|
|
|
|
"links": {
|
|
|
|
"version_downloads": "/api/v1/crates/postgres/downloads",
|
|
|
|
"versions": "/api/v1/crates/postgres/versions",
|
|
|
|
"owners": "/api/v1/crates/postgres/owners",
|
|
|
|
"owner_team": "/api/v1/crates/postgres/owner_team",
|
|
|
|
"owner_user": "/api/v1/crates/postgres/owner_user",
|
|
|
|
"reverse_dependencies": "/api/v1/crates/postgres/reverse_dependencies"
|
|
|
|
},
|
|
|
|
"exact_match": true
|
2014-12-16 17:18:40 +00:00
|
|
|
}
|
2022-06-09 03:04:33 +00:00
|
|
|
],
|
|
|
|
"meta": {
|
|
|
|
"total": 2
|
|
|
|
}
|
|
|
|
}"#;
|
2018-07-17 02:20:39 +00:00
|
|
|
|
2020-05-12 15:03:35 +00:00
|
|
|
const SEARCH_RESULTS: &str = "\
|
|
|
|
hoare = \"0.1.1\" # Design by contract style assertions for Rust
|
|
|
|
postgres = \"0.17.3\" # A native, synchronous PostgreSQL client
|
|
|
|
";
|
|
|
|
|
2022-06-09 03:04:33 +00:00
|
|
|
#[must_use]
|
|
|
|
fn setup() -> RegistryBuilder {
|
|
|
|
RegistryBuilder::new()
|
|
|
|
.http_api()
|
2022-09-09 20:58:58 +00:00
|
|
|
.add_responder("/api/v1/crates", |_, _| Response {
|
2022-06-09 03:04:33 +00:00
|
|
|
code: 200,
|
|
|
|
headers: vec![],
|
|
|
|
body: SEARCH_API_RESPONSE.to_vec(),
|
|
|
|
})
|
2018-07-17 02:20:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-17 02:20:39 +00:00
|
|
|
fn not_update() {
|
2022-06-09 03:04:33 +00:00
|
|
|
let registry = setup().build();
|
2018-07-17 02:20:39 +00:00
|
|
|
|
2023-08-18 22:45:25 +00:00
|
|
|
use cargo::core::{Shell, SourceId};
|
|
|
|
use cargo::sources::source::Source;
|
2018-07-17 02:20:39 +00:00
|
|
|
use cargo::sources::RegistrySource;
|
|
|
|
use cargo::util::Config;
|
|
|
|
|
2022-06-09 03:04:33 +00:00
|
|
|
let sid = SourceId::for_registry(registry.index_url()).unwrap();
|
2019-09-26 18:21:54 +00:00
|
|
|
let cfg = Config::new(
|
|
|
|
Shell::from_write(Box::new(Vec::new())),
|
|
|
|
paths::root(),
|
|
|
|
paths::home().join(".cargo"),
|
|
|
|
);
|
2023-09-07 04:01:18 +00:00
|
|
|
let lock = cfg
|
|
|
|
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)
|
|
|
|
.unwrap();
|
2022-03-09 22:10:22 +00:00
|
|
|
let mut regsrc = RegistrySource::remote(sid, &HashSet::new(), &cfg).unwrap();
|
2022-02-23 22:51:31 +00:00
|
|
|
regsrc.invalidate_cache();
|
|
|
|
regsrc.block_until_ready().unwrap();
|
2019-04-26 18:09:25 +00:00
|
|
|
drop(lock);
|
2018-07-17 02:20:39 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
cargo_process("search postgres")
|
2022-08-31 05:53:47 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2020-05-12 15:03:35 +00:00
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
2019-05-01 21:39:15 +00:00
|
|
|
.with_stderr("") // without "Updating ... index"
|
|
|
|
.run();
|
2018-07-17 02:20:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-17 02:20:39 +00:00
|
|
|
fn replace_default() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = setup().build();
|
2018-07-17 02:20:39 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
cargo_process("search postgres")
|
2022-08-31 05:53:47 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2020-05-12 15:03:35 +00:00
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
2018-09-08 08:25:41 +00:00
|
|
|
.with_stderr_contains("[..]Updating [..] index")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-07-17 02:20:39 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-07-17 02:20:39 +00:00
|
|
|
fn simple() {
|
2022-06-09 03:04:33 +00:00
|
|
|
let registry = setup().build();
|
2014-12-07 20:25:32 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
cargo_process("search postgres --index")
|
2022-06-09 03:04:33 +00:00
|
|
|
.arg(registry.index_url().as_str())
|
2020-05-12 15:03:35 +00:00
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2017-07-10 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn multiple_query_params() {
|
2022-06-09 03:04:33 +00:00
|
|
|
let registry = setup().build();
|
2015-04-08 18:33:15 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
cargo_process("search postgres sql --index")
|
2022-06-09 03:04:33 +00:00
|
|
|
.arg(registry.index_url().as_str())
|
2020-05-12 15:03:35 +00:00
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2022-02-26 01:10:48 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn ignore_quiet() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = setup().build();
|
2022-02-26 01:10:48 +00:00
|
|
|
|
|
|
|
cargo_process("search -q postgres")
|
2022-08-31 05:53:47 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2022-02-26 01:10:48 +00:00
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
|
|
|
.run();
|
|
|
|
}
|
2022-02-26 02:07:17 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn colored_results() {
|
2022-08-31 05:53:47 +00:00
|
|
|
let registry = setup().build();
|
2022-02-26 02:07:17 +00:00
|
|
|
|
|
|
|
cargo_process("search --color=never postgres")
|
2022-08-31 05:53:47 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2022-02-26 02:07:17 +00:00
|
|
|
.with_stdout_does_not_contain("[..]\x1b[[..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
cargo_process("search --color=always postgres")
|
2022-08-31 05:53:47 +00:00
|
|
|
.replace_crates_io(registry.index_url())
|
2022-02-26 02:07:17 +00:00
|
|
|
.with_stdout_contains("[..]\x1b[[..]")
|
|
|
|
.run();
|
|
|
|
}
|
2022-10-31 16:44:01 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn auth_required_failure() {
|
|
|
|
let server = setup().auth_required().no_configure_token().build();
|
|
|
|
|
2023-09-06 19:00:46 +00:00
|
|
|
cargo_process("search postgres")
|
2022-10-31 16:44:01 +00:00
|
|
|
.replace_crates_io(server.index_url())
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[ERROR] no token found, please run `cargo login`")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn auth_required() {
|
|
|
|
let server = setup().auth_required().build();
|
|
|
|
|
2023-09-06 19:00:46 +00:00
|
|
|
cargo_process("search postgres")
|
2022-10-31 16:44:01 +00:00
|
|
|
.replace_crates_io(server.index_url())
|
|
|
|
.with_stdout_contains(SEARCH_RESULTS)
|
|
|
|
.run();
|
|
|
|
}
|