Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin preparation for Rust 2018 #1467

Merged
merged 4 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use git2;
use oauth2;
use scheduled_thread_pool::ScheduledThreadPool;

use {db, Config};
use {db, Config, Env};

/// The `App` struct holds the main components of the application like
/// the database connection pool and configurations
Expand Down Expand Up @@ -56,25 +56,25 @@ impl App {

let db_pool_size = match (env::var("DB_POOL_SIZE"), config.env) {
(Ok(num), _) => num.parse().expect("couldn't parse DB_POOL_SIZE"),
(_, ::Env::Production) => 10,
(_, Env::Production) => 10,
_ => 1,
};

let db_min_idle = match (env::var("DB_MIN_IDLE"), config.env) {
(Ok(num), _) => Some(num.parse().expect("couldn't parse DB_MIN_IDLE")),
(_, ::Env::Production) => Some(5),
(_, Env::Production) => Some(5),
_ => None,
};

let db_helper_threads = match (env::var("DB_HELPER_THREADS"), config.env) {
(Ok(num), _) => num.parse().expect("couldn't parse DB_HELPER_THREADS"),
(_, ::Env::Production) => 3,
(_, Env::Production) => 3,
_ => 1,
};

let db_connection_timeout = match (env::var("DB_TIMEOUT"), config.env) {
(Ok(num), _) => num.parse().expect("couldn't parse DB_TIMEOUT"),
(_, ::Env::Production) => 10,
(_, Env::Production) => 10,
_ => 30,
};

Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Config {
pub gh_client_id: String,
pub gh_client_secret: String,
pub db_url: String,
pub env: ::Env,
pub env: Env,
pub max_upload_size: u64,
pub max_unpack_size: u64,
pub mirror: Replica,
Expand Down
4 changes: 2 additions & 2 deletions src/models/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use util::{human, CargoResult};

use models::{Crate, Version};
use schema::*;
use views::EncodableDependency;
use views::{EncodableCrateDependency, EncodableDependency};

#[derive(Identifiable, Associations, Debug)]
#[belongs_to(Version)]
Expand Down Expand Up @@ -75,7 +75,7 @@ impl ReverseDependency {

pub fn add_dependencies(
conn: &PgConnection,
deps: &[::views::EncodableCrateDependency],
deps: &[EncodableCrateDependency],
target_version_id: i32,
) -> CargoResult<Vec<git::Dependency>> {
use self::dependencies::dsl::*;
Expand Down
5 changes: 3 additions & 2 deletions src/models/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use diesel::prelude::*;

use models::User;
use schema::api_tokens;
use util::rfc3339;
use views::EncodableApiTokenWithToken;

/// The model representing a row in the `api_tokens` database table.
Expand All @@ -16,9 +17,9 @@ pub struct ApiToken {
#[serde(skip)]
pub token: String,
pub name: String,
#[serde(with = "::util::rfc3339")]
#[serde(with = "rfc3339")]
pub created_at: NaiveDateTime,
#[serde(with = "::util::rfc3339::option")]
#[serde(with = "rfc3339::option")]
pub last_used_at: Option<NaiveDateTime>,
}

Expand Down
12 changes: 6 additions & 6 deletions src/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ fn sign_in_as(req: &mut Request, user: &User) {

fn sign_in(req: &mut Request, app: &App) -> User {
let conn = app.diesel_database.get().unwrap();
let user = ::new_user("foo").create_or_update(&conn).unwrap();
let user = new_user("foo").create_or_update(&conn).unwrap();
sign_in_as(req, &user);
user
}
Expand Down Expand Up @@ -598,7 +598,7 @@ fn request_with_user_and_mock_crate(
let conn = app.diesel_database.get().unwrap();
let user = user.create_or_update(&conn).unwrap();
sign_in_as(&mut req, &user);
::CrateBuilder::new(krate, user.id).expect_build(&conn);
CrateBuilder::new(krate, user.id).expect_build(&conn);
}
req
}
Expand All @@ -624,7 +624,7 @@ fn new_req_full(
version: &str,
deps: Vec<u::CrateDependency>,
) -> MockRequest {
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
let mut req = req(app, Method::Put, "/api/v1/crates/new");
req.with_body(&new_req_body(
krate,
version,
Expand All @@ -642,7 +642,7 @@ fn new_req_with_keywords(
version: &str,
kws: Vec<String>,
) -> MockRequest {
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
let mut req = req(app, Method::Put, "/api/v1/crates/new");
req.with_body(&new_req_body(
krate,
version,
Expand All @@ -660,7 +660,7 @@ fn new_req_with_categories(
version: &str,
cats: Vec<String>,
) -> MockRequest {
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
let mut req = req(app, Method::Put, "/api/v1/crates/new");
req.with_body(&new_req_body(
krate,
version,
Expand All @@ -678,7 +678,7 @@ fn new_req_with_badges(
version: &str,
badges: HashMap<String, HashMap<String, String>>,
) -> MockRequest {
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
let mut req = req(app, Method::Put, "/api/v1/crates/new");
req.with_body(&new_req_body(
krate,
version,
Expand Down
9 changes: 4 additions & 5 deletions src/tests/badge.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::collections::HashMap;
use std::sync::Arc;

use App;

use models::{Badge, Crate, MaintenanceStatus};
use {app, new_user, App, CrateBuilder};

struct BadgeRef {
appveyor: Badge,
Expand All @@ -27,12 +26,12 @@ struct BadgeRef {
}

fn set_up() -> (Arc<App>, Crate, BadgeRef) {
let (_b, app, _middle) = ::app();
let (_b, app, _middle) = app();

let krate = {
let conn = app.diesel_database.get().unwrap();
let u = ::new_user("foo").create_or_update(&conn).unwrap();
::CrateBuilder::new("badged_crate", u.id).expect_build(&conn)
let u = new_user("foo").create_or_update(&conn).unwrap();
CrateBuilder::new("badged_crate", u.id).expect_build(&conn)
};

let appveyor = Badge::Appveyor {
Expand Down
39 changes: 20 additions & 19 deletions src/tests/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use conduit::{Handler, Method};

use models::Category;
use views::{EncodableCategory, EncodableCategoryWithSubcategories};
use {app, new_category, new_user, req, CrateBuilder};

#[derive(Deserialize)]
struct CategoryList {
Expand All @@ -26,8 +27,8 @@ use std::sync::Arc;

#[test]
fn index() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/categories");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/categories");

// List 0 categories if none exist
let mut response = ok_resp!(middle.call(&mut req));
Expand All @@ -38,10 +39,10 @@ fn index() {
// Create a category and a subcategory
{
let conn = t!(app.diesel_database.get());
::new_category("foo", "foo", "Foo crates")
new_category("foo", "foo", "Foo crates")
.create_or_update(&conn)
.unwrap();
::new_category("foo::bar", "foo::bar", "Bar crates")
new_category("foo::bar", "foo::bar", "Bar crates")
.create_or_update(&conn)
.unwrap();
}
Expand All @@ -57,19 +58,19 @@ fn index() {

#[test]
fn show() {
let (_b, app, middle) = ::app();
let (_b, app, middle) = app();

// Return not found if a category doesn't exist
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/categories/foo-bar");
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/categories/foo-bar");
let response = t_resp!(middle.call(&mut req));
assert_eq!(response.status.0, 404);

// Create a category and a subcategory
{
let conn = t!(app.diesel_database.get());

t!(::new_category("Foo Bar", "foo-bar", "Foo Bar crates").create_or_update(&conn));
t!(::new_category("Foo Bar::Baz", "foo-bar::baz", "Baz crates").create_or_update(&conn));
t!(new_category("Foo Bar", "foo-bar", "Foo Bar crates").create_or_update(&conn));
t!(new_category("Foo Bar::Baz", "foo-bar::baz", "Baz crates").create_or_update(&conn));
}

// The category and its subcategories should be in the json
Expand All @@ -83,8 +84,8 @@ fn show() {

#[test]
fn update_crate() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/categories/foo");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/categories/foo");
macro_rules! cnt {
($req:expr, $cat:expr) => {{
$req.with_path(&format!("/api/v1/categories/{}", $cat));
Expand All @@ -95,10 +96,10 @@ fn update_crate() {

let krate = {
let conn = t!(app.diesel_database.get());
let user = t!(::new_user("foo").create_or_update(&conn));
t!(::new_category("cat1", "cat1", "Category 1 crates").create_or_update(&conn));
t!(::new_category("Category 2", "category-2", "Category 2 crates").create_or_update(&conn));
::CrateBuilder::new("foo_crate", user.id).expect_build(&conn)
let user = t!(new_user("foo").create_or_update(&conn));
t!(new_category("cat1", "cat1", "Category 1 crates").create_or_update(&conn));
t!(new_category("Category 2", "category-2", "Category 2 crates").create_or_update(&conn));
CrateBuilder::new("foo_crate", user.id).expect_build(&conn)
};

// Updating with no categories has no effect
Expand Down Expand Up @@ -161,7 +162,7 @@ fn update_crate() {
// Add a category and its subcategory
{
let conn = t!(app.diesel_database.get());
t!(::new_category("cat1::bar", "cat1::bar", "bar crates").create_or_update(&conn,));
t!(new_category("cat1::bar", "cat1::bar", "bar crates").create_or_update(&conn,));
Category::update_crate(&conn, &krate, &["cat1", "cat1::bar"]).unwrap();
}
assert_eq!(cnt!(&mut req, "cat1"), 1);
Expand All @@ -171,18 +172,18 @@ fn update_crate() {

#[test]
fn category_slugs_returns_all_slugs_in_alphabetical_order() {
let (_b, app, middle) = ::app();
let (_b, app, middle) = app();
{
let conn = app.diesel_database.get().unwrap();
::new_category("Foo", "foo", "For crates that foo")
new_category("Foo", "foo", "For crates that foo")
.create_or_update(&conn)
.unwrap();
::new_category("Bar", "bar", "For crates that bar")
new_category("Bar", "bar", "For crates that bar")
.create_or_update(&conn)
.unwrap();
}

let mut req = ::req(app, Method::Get, "/api/v1/category_slugs");
let mut req = req(app, Method::Get, "/api/v1/category_slugs");

#[derive(Deserialize, Debug, PartialEq)]
struct Slug {
Expand Down
21 changes: 11 additions & 10 deletions src/tests/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use conduit_test::MockRequest;

use models::Keyword;
use views::EncodableKeyword;
use {app, new_user, req, CrateBuilder};

#[derive(Deserialize)]
struct KeywordList {
Expand All @@ -22,8 +23,8 @@ struct GoodKeyword {

#[test]
fn index() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/keywords");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/keywords");
let mut response = ok_resp!(middle.call(&mut req));
let json: KeywordList = ::json(&mut response);
assert_eq!(json.keywords.len(), 0);
Expand All @@ -42,8 +43,8 @@ fn index() {

#[test]
fn show() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/keywords/foo");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/keywords/foo");
let response = t_resp!(middle.call(&mut req));
assert_eq!(response.status.0, 404);

Expand All @@ -58,8 +59,8 @@ fn show() {

#[test]
fn uppercase() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/keywords/UPPER");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/keywords/UPPER");
{
let conn = app.diesel_database.get().unwrap();
Keyword::find_or_create_all(&conn, &["UPPER"]).unwrap();
Expand All @@ -72,8 +73,8 @@ fn uppercase() {

#[test]
fn update_crate() {
let (_b, app, middle) = ::app();
let mut req = ::req(Arc::clone(&app), Method::Get, "/api/v1/keywords/foo");
let (_b, app, middle) = app();
let mut req = req(Arc::clone(&app), Method::Get, "/api/v1/keywords/foo");
let cnt = |req: &mut MockRequest, kw: &str| {
req.with_path(&format!("/api/v1/keywords/{}", kw));
let mut response = ok_resp!(middle.call(req));
Expand All @@ -82,9 +83,9 @@ fn update_crate() {

let krate = {
let conn = app.diesel_database.get().unwrap();
let u = ::new_user("foo").create_or_update(&conn).unwrap();
let u = new_user("foo").create_or_update(&conn).unwrap();
Keyword::find_or_create_all(&conn, &["kw1", "kw2"]).unwrap();
::CrateBuilder::new("fookey", u.id).expect_build(&conn)
CrateBuilder::new("fookey", u.id).expect_build(&conn)
};

{
Expand Down
Loading