Skip to content

Commit 3f4670f

Browse files
committed
Extract a test helper method for uploading foo 2.0.0
1 parent 626de23 commit 3f4670f

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/tests/all.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ fn new_req_with_keywords(app: Arc<App>, krate: Crate, version: &str,
283283
return req;
284284
}
285285

286+
fn new_req_body_foo_version_2() -> Vec<u8> {
287+
new_req_body(::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new())
288+
}
289+
286290
fn new_req_body(krate: Crate, version: &str, deps: Vec<u::CrateDependency>,
287291
kws: Vec<String>, cats: Vec<String>) -> Vec<u8> {
288292
let kws = kws.into_iter().map(u::Keyword).collect();

src/tests/krate.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,7 @@ fn new_crate_owner() {
462462
assert_eq!(::json::<CrateList>(&mut response).crates.len(), 1);
463463

464464
// And upload a new crate as the first user
465-
let body = ::new_req_body(
466-
::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new()
467-
);
465+
let body = ::new_req_body_foo_version_2();
468466
req.mut_extensions().insert(u2);
469467
let mut response = ok_resp!(middle.call(req.with_path("/api/v1/crates/new")
470468
.with_method(Method::Put)

src/tests/team.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ fn remove_team_as_named_owner() {
134134
.with_body(body.as_bytes())));
135135

136136
::mock_user(&mut req, mock_user_on_only_x());
137-
let body = ::new_req_body(
138-
::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new()
139-
);
137+
let body = ::new_req_body_foo_version_2();
140138
let json = bad_resp!(middle.call(req.with_path("/api/v1/crates/new")
141139
.with_body(&body)
142140
.with_method(Method::Put)));
@@ -166,9 +164,7 @@ fn remove_team_as_team_owner() {
166164
assert!(json.errors[0].detail.contains("don't have permission"),
167165
"{:?}", json.errors);
168166

169-
let body = ::new_req_body(
170-
::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new()
171-
);
167+
let body = ::new_req_body_foo_version_2();
172168
ok_resp!(middle.call(req.with_path("/api/v1/crates/new")
173169
.with_body(&body)
174170
.with_method(Method::Put)));
@@ -189,9 +185,7 @@ fn publish_not_owned() {
189185
.with_body(body.as_bytes())));
190186

191187
::mock_user(&mut req, mock_user_on_only_x());
192-
let body = ::new_req_body(
193-
::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new()
194-
);
188+
let body = ::new_req_body_foo_version_2();
195189
let json = bad_resp!(middle.call(req.with_path("/api/v1/crates/new")
196190
.with_body(&body)
197191
.with_method(Method::Put)));
@@ -213,9 +207,7 @@ fn publish_owned() {
213207
.with_body(body.as_bytes())));
214208

215209
::mock_user(&mut req, mock_user_on_only_x());
216-
let body = ::new_req_body(
217-
::krate("foo"), "2.0.0", Vec::new(), Vec::new(), Vec::new()
218-
);
210+
let body = ::new_req_body_foo_version_2();
219211
ok_resp!(middle.call(req.with_path("/api/v1/crates/new")
220212
.with_body(&body)
221213
.with_method(Method::Put)));

0 commit comments

Comments
 (0)