Skip to content

Commit df7122f

Browse files
committed
Switch to no proxy by default for tests
The remaining 12 tests that call `app()` directly do not need a proxy.
1 parent 28254b8 commit df7122f

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

src/tests/all.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,22 @@ pub struct OkBool {
108108
ok: bool,
109109
}
110110

111-
fn app() -> (
111+
/// Initialize the app and a proxy that can record and playback outgoing HTTP requests
112+
fn app_with_proxy() -> (
112113
record::Bomb,
113114
Arc<App>,
114115
conduit_middleware::MiddlewareBuilder,
115116
) {
116117
let (proxy, bomb) = record::proxy();
117-
let (app, handler) = simple_app(Some(proxy));
118+
let (app, handler) = init_app(Some(proxy));
118119
(bomb, app, handler)
119120
}
120121

121-
fn simple_app(proxy: Option<String>) -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
122+
fn app() -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
123+
init_app(None)
124+
}
125+
126+
fn init_app(proxy: Option<String>) -> (Arc<App>, conduit_middleware::MiddlewareBuilder) {
122127
let uploader = Uploader::S3 {
123128
bucket: s3::Bucket::new(
124129
String::from("alexcrichton-test"),
@@ -287,7 +292,7 @@ fn logout(req: &mut dyn Request) {
287292
fn multiple_live_references_to_the_same_connection_can_be_checked_out() {
288293
use std::ptr;
289294

290-
let (_bomb, app, _) = app();
295+
let (app, _) = app();
291296
let conn1 = app.diesel_database.get().unwrap();
292297
let conn2 = app.diesel_database.get().unwrap();
293298
let conn1_ref: &PgConnection = &conn1;

src/tests/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn show() {
7676
#[test]
7777
#[allow(clippy::cyclomatic_complexity)]
7878
fn update_crate() {
79-
let (_b, app, middle) = app();
79+
let (app, middle) = app();
8080
let mut req = req(Method::Get, "/api/v1/categories/foo");
8181
macro_rules! cnt {
8282
($req:expr, $cat:expr) => {{

src/tests/owners.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn test_accept_invitation() {
235235
crate_owner_invitation: InvitationResponse,
236236
}
237237

238-
let (_b, app, middle) = app();
238+
let (app, middle) = app();
239239
let mut req = req(Method::Get, "/api/v1/me/crate_owner_invitations");
240240
let (krate, user) = {
241241
let conn = app.diesel_database.get().unwrap();
@@ -315,7 +315,7 @@ fn test_decline_invitation() {
315315
crate_owner_invitation: InvitationResponse,
316316
}
317317

318-
let (_b, app, middle) = app();
318+
let (app, middle) = app();
319319
let mut req = req(Method::Get, "/api/v1/me/crate_owner_invitations");
320320
let (krate, user) = {
321321
let conn = app.diesel_database.get().unwrap();

src/tests/user.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn updating_existing_user_doesnt_change_api_token() {
293293
*/
294294
#[test]
295295
fn test_github_login_does_not_overwrite_email() {
296-
let (_b, app, middle) = app();
296+
let (app, middle) = app();
297297
let mut req = req(Method::Get, "/api/v1/me");
298298
let user = {
299299
let conn = app.diesel_database.get().unwrap();
@@ -343,7 +343,7 @@ fn test_github_login_does_not_overwrite_email() {
343343
*/
344344
#[test]
345345
fn test_email_get_and_put() {
346-
let (_b, app, middle) = app();
346+
let (app, middle) = app();
347347
let mut req = req(Method::Get, "/api/v1/me");
348348
let user = {
349349
let conn = app.diesel_database.get().unwrap();
@@ -386,7 +386,7 @@ fn test_email_get_and_put() {
386386
*/
387387
#[test]
388388
fn test_empty_email_not_added() {
389-
let (_b, app, middle) = app();
389+
let (app, middle) = app();
390390
let mut req = req(Method::Get, "/api/v1/me");
391391
let user = {
392392
let conn = app.diesel_database.get().unwrap();
@@ -434,7 +434,7 @@ fn test_empty_email_not_added() {
434434
*/
435435
#[test]
436436
fn test_this_user_cannot_change_that_user_email() {
437-
let (_b, app, middle) = app();
437+
let (app, middle) = app();
438438
let mut req = req(Method::Get, "/api/v1/me");
439439

440440
let not_signed_in_user = {
@@ -471,7 +471,7 @@ fn test_this_user_cannot_change_that_user_email() {
471471
*/
472472
#[test]
473473
fn test_insert_into_email_table() {
474-
let (_b, app, middle) = app();
474+
let (app, middle) = app();
475475
let mut req = req(Method::Get, "/me");
476476
let user = {
477477
let conn = app.diesel_database.get().unwrap();
@@ -518,7 +518,7 @@ fn test_insert_into_email_table() {
518518
*/
519519
#[test]
520520
fn test_insert_into_email_table_with_email_change() {
521-
let (_b, app, middle) = app();
521+
let (app, middle) = app();
522522
let mut req = req(Method::Get, "/me");
523523
let user = {
524524
let conn = app.diesel_database.get().unwrap();
@@ -581,7 +581,7 @@ fn test_insert_into_email_table_with_email_change() {
581581
fn test_confirm_user_email() {
582582
use cargo_registry::schema::emails;
583583

584-
let (_b, app, middle) = app();
584+
let (app, middle) = app();
585585
let mut req = req(Method::Get, "/me");
586586
let user = {
587587
let conn = app.diesel_database.get().unwrap();
@@ -627,7 +627,7 @@ fn test_existing_user_email() {
627627
use chrono::NaiveDateTime;
628628
use diesel::update;
629629

630-
let (_b, app, middle) = app();
630+
let (app, middle) = app();
631631
let mut req = req(Method::Get, "/me");
632632
{
633633
let conn = app.diesel_database.get().unwrap();

src/tests/util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
//! to the underlying database model value (`User` and `ApiToken` respectively).
2121
2222
use crate::{
23-
app, builders::PublishBuilder, record, CrateList, CrateResponse, GoodCrate, OkBool,
24-
VersionResponse,
23+
app, app_with_proxy, builders::PublishBuilder, record, CrateList, CrateResponse, GoodCrate,
24+
OkBool, VersionResponse,
2525
};
2626
use cargo_registry::{
2727
background_jobs::{job_runner, Environment},
@@ -93,7 +93,7 @@ pub struct TestApp(Rc<TestAppInner>);
9393
impl TestApp {
9494
/// Initialize an application with an `Uploader` that panics
9595
pub fn init() -> TestAppBuilder {
96-
let (app, middle) = crate::simple_app(None);
96+
let (app, middle) = app();
9797
let inner = Rc::new(TestAppInner {
9898
app,
9999
_bomb: None,
@@ -106,7 +106,7 @@ impl TestApp {
106106

107107
/// Initialize the app and a proxy that can record and playback outgoing HTTP requests
108108
pub fn with_proxy() -> TestAppBuilder {
109-
let (bomb, app, middle) = app();
109+
let (bomb, app, middle) = app_with_proxy();
110110
let inner = Rc::new(TestAppInner {
111111
app,
112112
_bomb: Some(bomb),
@@ -121,7 +121,7 @@ impl TestApp {
121121
pub fn full() -> TestAppBuilder {
122122
use crate::git;
123123

124-
let (bomb, app, middle) = app();
124+
let (bomb, app, middle) = app_with_proxy();
125125
git::init();
126126

127127
let thread_local_path = git::bare();

0 commit comments

Comments
 (0)