Skip to content

Commit 4d30d52

Browse files
committed
Modified tests to use '--index' instead of '--host', added test to support using '--host' with warning message, added test to support using both '--host' and '--index' with warning message for host
1 parent 624b6f2 commit 4d30d52

File tree

1 file changed

+134
-1
lines changed

1 file changed

+134
-1
lines changed

tests/search.rs

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,141 @@ fn simple() {
8282
}
8383

8484
assert_that(cargo_process("search").arg("postgres")
85+
.arg("--index").arg(registry().to_string()),
86+
execs().with_status(0)
87+
.with_stdout_contains("\
88+
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
89+
}
90+
91+
// TODO: Depricated
92+
// remove once it has been decided '--host' can be safely removed
93+
#[test]
94+
fn simple_with_host() {
95+
setup();
96+
97+
let contents = r#"{
98+
"crates": [{
99+
"created_at": "2014-11-16T20:17:35Z",
100+
"description": "Design by contract style assertions for Rust",
101+
"documentation": null,
102+
"downloads": 2,
103+
"homepage": null,
104+
"id": "hoare",
105+
"keywords": [],
106+
"license": null,
107+
"links": {
108+
"owners": "/api/v1/crates/hoare/owners",
109+
"reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
110+
"version_downloads": "/api/v1/crates/hoare/downloads",
111+
"versions": "/api/v1/crates/hoare/versions"
112+
},
113+
"max_version": "0.1.1",
114+
"name": "hoare",
115+
"repository": "https://github.com/nick29581/libhoare",
116+
"updated_at": "2014-11-20T21:49:21Z",
117+
"versions": null
118+
}],
119+
"meta": {
120+
"total": 1
121+
}
122+
}"#;
123+
let base = api_path().join("api/v1/crates");
124+
125+
// Older versions of curl don't peel off query parameters when looking for
126+
// filenames, so just make both files.
127+
//
128+
// On windows, though, `?` is an invalid character, but we always build curl
129+
// from source there anyway!
130+
File::create(&base).unwrap().write_all(contents.as_bytes()).unwrap();
131+
if !cfg!(windows) {
132+
File::create(&base.with_file_name("crates?q=postgres&per_page=10")).unwrap()
133+
.write_all(contents.as_bytes()).unwrap();
134+
}
135+
136+
assert_that(cargo_process("search").arg("postgres")
137+
.arg("--host").arg(registry().to_string()),
138+
execs().with_status(0)
139+
.with_stderr(&format!("\
140+
[WARNING] The flag '--host' is no longer valid.
141+
142+
Previous versions of Cargo accepted this flag, but it is being
143+
depricated. The flag is being renamed to 'index', as the flag
144+
wants the location of the index in which to search. Please
145+
use '--index' instead.
146+
147+
This will soon become a hard error, so it's either recommended
148+
to update to a fixed version or contact the upstream maintainer
149+
about this warning.
150+
[UPDATING] registry `{reg}`
151+
",
152+
reg = registry()))
153+
.with_stdout_contains("\
154+
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
155+
}
156+
157+
// TODO: Depricated
158+
// remove once it has been decided '--host' can be safely removed
159+
#[test]
160+
fn simple_with_index_and_host() {
161+
setup();
162+
163+
let contents = r#"{
164+
"crates": [{
165+
"created_at": "2014-11-16T20:17:35Z",
166+
"description": "Design by contract style assertions for Rust",
167+
"documentation": null,
168+
"downloads": 2,
169+
"homepage": null,
170+
"id": "hoare",
171+
"keywords": [],
172+
"license": null,
173+
"links": {
174+
"owners": "/api/v1/crates/hoare/owners",
175+
"reverse_dependencies": "/api/v1/crates/hoare/reverse_dependencies",
176+
"version_downloads": "/api/v1/crates/hoare/downloads",
177+
"versions": "/api/v1/crates/hoare/versions"
178+
},
179+
"max_version": "0.1.1",
180+
"name": "hoare",
181+
"repository": "https://github.com/nick29581/libhoare",
182+
"updated_at": "2014-11-20T21:49:21Z",
183+
"versions": null
184+
}],
185+
"meta": {
186+
"total": 1
187+
}
188+
}"#;
189+
let base = api_path().join("api/v1/crates");
190+
191+
// Older versions of curl don't peel off query parameters when looking for
192+
// filenames, so just make both files.
193+
//
194+
// On windows, though, `?` is an invalid character, but we always build curl
195+
// from source there anyway!
196+
File::create(&base).unwrap().write_all(contents.as_bytes()).unwrap();
197+
if !cfg!(windows) {
198+
File::create(&base.with_file_name("crates?q=postgres&per_page=10")).unwrap()
199+
.write_all(contents.as_bytes()).unwrap();
200+
}
201+
202+
assert_that(cargo_process("search").arg("postgres")
203+
.arg("--index").arg(registry().to_string())
85204
.arg("--host").arg(registry().to_string()),
86205
execs().with_status(0)
206+
.with_stderr(&format!("\
207+
[WARNING] The flag '--host' is no longer valid.
208+
209+
Previous versions of Cargo accepted this flag, but it is being
210+
depricated. The flag is being renamed to 'index', as the flag
211+
wants the location of the index in which to search. Please
212+
use '--index' instead.
213+
214+
This will soon become a hard error, so it's either recommended
215+
to update to a fixed version or contact the upstream maintainer
216+
about this warning.
217+
[UPDATING] registry `{reg}`
218+
",
219+
reg = registry()))
87220
.with_stdout_contains("\
88221
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));
89222
}
@@ -132,7 +265,7 @@ fn multiple_query_params() {
132265
}
133266

134267
assert_that(cargo_process("search").arg("postgres").arg("sql")
135-
.arg("--host").arg(registry().to_string()),
268+
.arg("--index").arg(registry().to_string()),
136269
execs().with_status(0)
137270
.with_stdout_contains("\
138271
hoare = \"0.1.1\" # Design by contract style assertions for Rust"));

0 commit comments

Comments
 (0)