From 2b8f7192865ed90abc3abc5dee94852149de9ba6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 7 Jan 2020 22:34:56 -0500 Subject: [PATCH 01/13] Fix occasional panic when visiting settings.html Closes https://github.com/rust-lang/docs.rs/issues/552 --- src/web/rustdoc.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 31d94ed44..710040f97 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -311,8 +311,13 @@ fn path_for_version(req_path: &[&str], target_name: &str, conn: &Connection) -> .expect("paths should be of the form ..html") }; // check if req_path[3] is the platform choice or the name of the crate + // rustdoc generates a ../settings.html page; + // if we get this far and we're on settings.html, there is no module. + // additionally, if settings.html doesn't exist on the most recent page, + // the build must have failed, so we just redirect to the root page. let concat_path; - let crate_root = if req_path[3] != target_name { + let crate_root = if req_path[3] != target_name && req_path[3] != "settings.html" { + assert!(req_path.len() >= 5, "{:?}", req_path); concat_path = format!("{}/{}", req_path[3], req_path[4]); &concat_path } else { From a5fdc4bb4683a809e9a020486c23e885c55c5329 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 16:31:09 -0500 Subject: [PATCH 02/13] don't hang forever on test panics --- src/test/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index 7b6e537b2..f7d8e5982 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -8,9 +8,15 @@ use reqwest::{Client, Method, RequestBuilder}; use std::sync::{Arc, Mutex, MutexGuard}; pub(crate) fn wrapper(f: impl FnOnce(&TestEnvironment) -> Result<(), Error>) { + use std::panic; let env = TestEnvironment::new(); - let result = f(&env); + // if we didn't catch the panic, the server would hang forever + let maybe_panic = panic::catch_unwind(panic::AssertUnwindSafe(|| f(&env))); env.cleanup(); + let result = match maybe_panic { + Ok(r) => r, + Err(payload) => panic::resume_unwind(payload), + }; if let Err(err) = result { eprintln!("the test failed: {}", err); From b51a6fc1cb1b0ce95e7609c996e08d482e9285e0 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 20:42:24 -0500 Subject: [PATCH 03/13] Allow adding files to FakeReleases Useful when testing rustdoc pages --- src/test/fakes.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index ac3ed6925..b2a599539 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -5,11 +5,12 @@ use crate::utils::{Dependency, MetadataPackage, Target}; use failure::Error; use rustc_serialize::json::Json; +#[must_use = "FakeRelease does nothing until you call .create()"] pub(crate) struct FakeRelease<'db> { db: &'db TestDatabase, package: MetadataPackage, build_result: BuildResult, - files: Option, + files: Vec<(String, String, Vec)>, doc_targets: Vec, default_target: Option, cratesio_data: CratesIoData, @@ -46,7 +47,7 @@ impl<'db> FakeRelease<'db> { build_log: "It works!".into(), successful: true, }, - files: None, + files: Vec::new(), doc_targets: Vec::new(), default_target: None, cratesio_data: CratesIoData { @@ -81,15 +82,36 @@ impl<'db> FakeRelease<'db> { self } + pub(crate) fn file(mut self, mimetype: M, path: P, data: D) -> Self + where M: Into, + P: Into, + D: Into>, + { + let (mimetype, path, data) = (mimetype.into(), path.into(), data.into()); + if mimetype.contains('"') || path.contains('"') { + panic!("invalid mimetype or path: {}, {}", mimetype, path); + } + self.files.push((mimetype, path, data)); + self + } + pub(crate) fn create(self) -> Result { let tempdir = tempdir::TempDir::new("docs.rs-fake")?; + let files: Vec<_> = self.files.into_iter().map(|(mimetype, path, data)| { + let file = tempdir.path().join(&path); + std::fs::write(file, data)?; + + let metadata = format!("[\"{}\", \"{}\"]", mimetype, path); + Ok(Json::from_str(&metadata).expect("should be valid json")) + }).collect::>()?; + let release_id = crate::db::add_package_into_database( &self.db.conn(), &self.package, tempdir.path(), &self.build_result, - self.files, + if files.is_empty() { None } else { Some(Json::Array(files)) }, self.doc_targets, &self.default_target, &self.cratesio_data, @@ -98,6 +120,10 @@ impl<'db> FakeRelease<'db> { )?; crate::db::add_build_into_database(&self.db.conn(), &release_id, &self.build_result)?; + let prefix = format!("rustdoc/{}/{}", self.package.name, self.package.version); + let added_files = crate::db::add_path_into_database(&self.db.conn(), &prefix, tempdir.path())?; + log::debug!("added files {}", added_files); + Ok(release_id) } } From 700d63eb48bbedcea7d89a631577c17f3ca8468c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 20:45:57 -0500 Subject: [PATCH 04/13] Test that panic is actually fixed --- src/test/mod.rs | 7 +++++++ src/web/rustdoc.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/test/mod.rs b/src/test/mod.rs index f7d8e5982..6102ad1a9 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -30,6 +30,13 @@ pub(crate) fn wrapper(f: impl FnOnce(&TestEnvironment) -> Result<(), Error>) { } } +/// Make sure that a URL returns a status code between 200-299 +pub(crate) fn assert_success(path: &str, web: &TestFrontend) -> Result<(), Error> { + let status = web.get(path).send()?.status(); + assert!(status.is_success(), "failed to GET {}: {}", path, status); + Ok(()) +} + pub(crate) struct TestEnvironment { db: OnceCell, frontend: OnceCell, diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 710040f97..5796e24bc 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -413,3 +413,32 @@ impl Handler for SharedResourceHandler { Err(IronError::new(Nope::ResourceNotFound, status::NotFound)) } } + +#[cfg(test)] +mod test { + use crate::test::*; + #[test] + // regression test for https://github.com/rust-lang/docs.rs/issues/552 + fn settings_html() { + wrapper(|env| { + let db = env.db(); + // first release works, second fails + db.fake_release() + .name("buggy").version("0.1.0") + .build_result_successful(true) + .file("text/html", "settings.html", "some data") + .file("text/html", "all.html", "some data 2") + .create()?; + db.fake_release() + .name("buggy").version("0.2.0") + .build_result_successful(false) + .create()?; + let web = env.frontend(); + assert_success("/", web)?; + assert_success("/crate/buggy/0.1.0/", web)?; + assert_success("/buggy/0.1.0/settings.html", web)?; + assert_success("/buggy/0.1.0/all.html", web)?; + Ok(()) + }); + } +} \ No newline at end of file From 6edaa4f3e1025f1d3cb2f38662600d00a54072d7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 8 Jan 2020 20:46:55 -0500 Subject: [PATCH 05/13] fix the 2nd panic good thing I wrote the tests :) --- src/web/rustdoc.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 5796e24bc..272e557fe 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -311,13 +311,12 @@ fn path_for_version(req_path: &[&str], target_name: &str, conn: &Connection) -> .expect("paths should be of the form ..html") }; // check if req_path[3] is the platform choice or the name of the crate - // rustdoc generates a ../settings.html page; - // if we get this far and we're on settings.html, there is no module. - // additionally, if settings.html doesn't exist on the most recent page, - // the build must have failed, so we just redirect to the root page. + // rustdoc generates a ../settings.html page, so if req_path[3] is not + // the target, that doesn't necessarily mean it's a platform. + // we also can't check if it's in TARGETS, since some targets have been + // removed (looking at you, i686-apple-darwin) let concat_path; - let crate_root = if req_path[3] != target_name && req_path[3] != "settings.html" { - assert!(req_path.len() >= 5, "{:?}", req_path); + let crate_root = if req_path[3] != target_name && req_path.len() >= 5 { concat_path = format!("{}/{}", req_path[3], req_path[4]); &concat_path } else { From 7f709b07613196aebf8ab3955fa496855aac5de8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 06:51:37 -0500 Subject: [PATCH 06/13] address review comments --- src/test/fakes.rs | 6 +----- src/test/mod.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index b2a599539..292694344 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -88,9 +88,6 @@ impl<'db> FakeRelease<'db> { D: Into>, { let (mimetype, path, data) = (mimetype.into(), path.into(), data.into()); - if mimetype.contains('"') || path.contains('"') { - panic!("invalid mimetype or path: {}, {}", mimetype, path); - } self.files.push((mimetype, path, data)); self } @@ -102,8 +99,7 @@ impl<'db> FakeRelease<'db> { let file = tempdir.path().join(&path); std::fs::write(file, data)?; - let metadata = format!("[\"{}\", \"{}\"]", mimetype, path); - Ok(Json::from_str(&metadata).expect("should be valid json")) + Ok(Json::Array(vec![Json::String(mimetype), Json::String(path)])) }).collect::>()?; let release_id = crate::db::add_package_into_database( diff --git a/src/test/mod.rs b/src/test/mod.rs index 6102ad1a9..6ea7a097d 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -6,9 +6,9 @@ use once_cell::unsync::OnceCell; use postgres::Connection; use reqwest::{Client, Method, RequestBuilder}; use std::sync::{Arc, Mutex, MutexGuard}; +use std::panic; pub(crate) fn wrapper(f: impl FnOnce(&TestEnvironment) -> Result<(), Error>) { - use std::panic; let env = TestEnvironment::new(); // if we didn't catch the panic, the server would hang forever let maybe_panic = panic::catch_unwind(panic::AssertUnwindSafe(|| f(&env))); From 7caca21e29d0597b2240be37d716d023f95f39f1 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 07:29:10 -0500 Subject: [PATCH 07/13] files -> source files --- src/db/add_package.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/db/add_package.rs b/src/db/add_package.rs index 359361a22..3e6acd08f 100644 --- a/src/db/add_package.rs +++ b/src/db/add_package.rs @@ -22,11 +22,14 @@ use failure::err_msg; /// Adds a package into database. /// /// Package must be built first. +/// +/// NOTE: `source_files` refers to the files originally in the crate, +/// not the files generated by rustdoc. pub(crate) fn add_package_into_database(conn: &Connection, metadata_pkg: &MetadataPackage, source_dir: &Path, res: &BuildResult, - files: Option, + source_files: Option, doc_targets: Vec, default_target: &Option, cratesio_data: &CratesIoData, @@ -78,7 +81,7 @@ pub(crate) fn add_package_into_database(conn: &Connection, &metadata_pkg.keywords.to_json(), &has_examples, &cratesio_data.downloads, - &files, + &source_files, &doc_targets.to_json(), &is_library, &res.rustc_version, @@ -132,7 +135,7 @@ pub(crate) fn add_package_into_database(conn: &Connection, &metadata_pkg.keywords.to_json(), &has_examples, &cratesio_data.downloads, - &files, + &source_files, &doc_targets.to_json(), &is_library, &res.rustc_version, From 0c6804d300bef4436b407f3b4456e826f2da0d41 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 07:29:55 -0500 Subject: [PATCH 08/13] add more doc-comments for `add_path_into_database` --- src/db/file.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/db/file.rs b/src/db/file.rs index 262d96f89..ad3609e46 100644 --- a/src/db/file.rs +++ b/src/db/file.rs @@ -142,7 +142,15 @@ pub(super) fn s3_client() -> Option { )) } -/// Adds files into database and returns list of files with their mime type in Json +/// Store all files in a directory and return [[mimetype, filename]] as Json +/// +/// If there is an S3 Client configured, store files into an S3 bucket; +/// otherwise, stores files into the 'files' table of the local database. +/// +/// The mimetype is detected using `magic`. +/// +/// Note that this function is used for uploading both sources +/// and files generated by rustdoc. pub fn add_path_into_database>(conn: &Connection, prefix: &str, path: P) From 8646073d9d1df5502e831fec6b54a49065b81404 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 07:30:37 -0500 Subject: [PATCH 09/13] Fix rustdoc files for FakeRelease rustdoc files and source files are different --- src/test/fakes.rs | 43 ++++++++++++++++++++++++++++++------------- src/web/rustdoc.rs | 4 ++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index 292694344..e3d120d8d 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -3,14 +3,16 @@ use crate::db::CratesIoData; use crate::docbuilder::BuildResult; use crate::utils::{Dependency, MetadataPackage, Target}; use failure::Error; -use rustc_serialize::json::Json; #[must_use = "FakeRelease does nothing until you call .create()"] pub(crate) struct FakeRelease<'db> { db: &'db TestDatabase, package: MetadataPackage, build_result: BuildResult, - files: Vec<(String, String, Vec)>, + /// name, content + source_files: Vec<(String, Vec)>, + /// name, content + rustdoc_files: Vec<(String, Vec)>, doc_targets: Vec, default_target: Option, cratesio_data: CratesIoData, @@ -47,7 +49,8 @@ impl<'db> FakeRelease<'db> { build_log: "It works!".into(), successful: true, }, - files: Vec::new(), + source_files: Vec::new(), + rustdoc_files: Vec::new(), doc_targets: Vec::new(), default_target: None, cratesio_data: CratesIoData { @@ -92,22 +95,40 @@ impl<'db> FakeRelease<'db> { self } + pub(crate) fn rustdoc_file(mut self, path: P, data: D) -> Self + where P: Into, + D: Into>, + { + let (path, data) = (path.into(), data.into()); + self.rustdoc_files.push((path, data)); + + self + } + pub(crate) fn create(self) -> Result { let tempdir = tempdir::TempDir::new("docs.rs-fake")?; - let files: Vec<_> = self.files.into_iter().map(|(mimetype, path, data)| { - let file = tempdir.path().join(&path); - std::fs::write(file, data)?; + let upload_files = |prefix, files: Vec<(String, Vec)>, package: &MetadataPackage, db: &TestDatabase| { + for (path, data) in files { + let file = tempdir.path().join(&path); + std::fs::write(file, data)?; + } - Ok(Json::Array(vec![Json::String(mimetype), Json::String(path)])) - }).collect::>()?; + let prefix = format!("{}/{}/{}", prefix, package.name, package.version); + crate::db::add_path_into_database(&db.conn(), &prefix, tempdir.path()) + }; + + let rustdoc_meta = upload_files("rustdoc", self.rustdoc_files, &self.package, self.db)?; + log::debug!("added rustdoc files {}", rustdoc_meta); + let source_meta = upload_files("source", self.source_files, &self.package, self.db)?; + log::debug!("added source files {}", source_meta); let release_id = crate::db::add_package_into_database( &self.db.conn(), &self.package, tempdir.path(), &self.build_result, - if files.is_empty() { None } else { Some(Json::Array(files)) }, + Some(source_meta), self.doc_targets, &self.default_target, &self.cratesio_data, @@ -116,10 +137,6 @@ impl<'db> FakeRelease<'db> { )?; crate::db::add_build_into_database(&self.db.conn(), &release_id, &self.build_result)?; - let prefix = format!("rustdoc/{}/{}", self.package.name, self.package.version); - let added_files = crate::db::add_path_into_database(&self.db.conn(), &prefix, tempdir.path())?; - log::debug!("added files {}", added_files); - Ok(release_id) } } diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 272e557fe..f6dfc49dd 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -425,8 +425,8 @@ mod test { db.fake_release() .name("buggy").version("0.1.0") .build_result_successful(true) - .file("text/html", "settings.html", "some data") - .file("text/html", "all.html", "some data 2") + .rustdoc_file("settings.html", "some data") + .rustdoc_file("all.html", "some data 2") .create()?; db.fake_release() .name("buggy").version("0.2.0") From 4d32ca2b3ecb67404e247d888295d673a0f8dd4d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 07:37:53 -0500 Subject: [PATCH 10/13] don't duplicate rustdoc files as source files --- src/test/fakes.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index e3d120d8d..9b639b8c7 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -108,14 +108,17 @@ impl<'db> FakeRelease<'db> { pub(crate) fn create(self) -> Result { let tempdir = tempdir::TempDir::new("docs.rs-fake")?; - let upload_files = |prefix, files: Vec<(String, Vec)>, package: &MetadataPackage, db: &TestDatabase| { + let upload_files = |prefix: &str, files: Vec<(String, Vec)>, package: &MetadataPackage, db: &TestDatabase| { + let path_prefix = tempdir.path().join(prefix); + std::fs::create_dir(&path_prefix)?; + for (path, data) in files { - let file = tempdir.path().join(&path); + let file = path_prefix.join(&path); std::fs::write(file, data)?; } let prefix = format!("{}/{}/{}", prefix, package.name, package.version); - crate::db::add_path_into_database(&db.conn(), &prefix, tempdir.path()) + crate::db::add_path_into_database(&db.conn(), &prefix, path_prefix) }; let rustdoc_meta = upload_files("rustdoc", self.rustdoc_files, &self.package, self.db)?; From 9606e552e40b2d62d2975721b2782ce5d560b393 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 9 Jan 2020 07:40:30 -0500 Subject: [PATCH 11/13] clean up code a little --- src/test/fakes.rs | 4 +--- src/web/rustdoc.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index 9b639b8c7..b9d6bb348 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -99,9 +99,7 @@ impl<'db> FakeRelease<'db> { where P: Into, D: Into>, { - let (path, data) = (path.into(), data.into()); - self.rustdoc_files.push((path, data)); - + self.rustdoc_files.push((path.into(), data.into())); self } diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index f6dfc49dd..3f202eebd 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -440,4 +440,4 @@ mod test { Ok(()) }); } -} \ No newline at end of file +} From 7d3828b8aba27afb584a9e5e56a98476955aeac5 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 10 Jan 2020 10:40:25 -0500 Subject: [PATCH 12/13] simplify closure for test fakes --- src/test/fakes.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index b9d6bb348..e0f63f09d 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -106,7 +106,7 @@ impl<'db> FakeRelease<'db> { pub(crate) fn create(self) -> Result { let tempdir = tempdir::TempDir::new("docs.rs-fake")?; - let upload_files = |prefix: &str, files: Vec<(String, Vec)>, package: &MetadataPackage, db: &TestDatabase| { + let upload_files = |prefix: &str, files: &[(String, Vec)]| { let path_prefix = tempdir.path().join(prefix); std::fs::create_dir(&path_prefix)?; @@ -115,13 +115,13 @@ impl<'db> FakeRelease<'db> { std::fs::write(file, data)?; } - let prefix = format!("{}/{}/{}", prefix, package.name, package.version); - crate::db::add_path_into_database(&db.conn(), &prefix, path_prefix) + let prefix = format!("{}/{}/{}", prefix, self.package.name, self.package.version); + crate::db::add_path_into_database(&self.db.conn(), &prefix, path_prefix) }; - let rustdoc_meta = upload_files("rustdoc", self.rustdoc_files, &self.package, self.db)?; + let rustdoc_meta = upload_files("rustdoc", &self.rustdoc_files)?; log::debug!("added rustdoc files {}", rustdoc_meta); - let source_meta = upload_files("source", self.source_files, &self.package, self.db)?; + let source_meta = upload_files("source", &self.source_files)?; log::debug!("added source files {}", source_meta); let release_id = crate::db::add_package_into_database( From dd6d8710513e2486133b93cf18461b42fc8c0e2f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 10 Jan 2020 10:45:08 -0500 Subject: [PATCH 13/13] do less copying for test struct --- src/test/fakes.rs | 31 +++++++++---------------------- src/web/rustdoc.rs | 4 ++-- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/test/fakes.rs b/src/test/fakes.rs index e0f63f09d..fc4957820 100644 --- a/src/test/fakes.rs +++ b/src/test/fakes.rs @@ -5,14 +5,14 @@ use crate::utils::{Dependency, MetadataPackage, Target}; use failure::Error; #[must_use = "FakeRelease does nothing until you call .create()"] -pub(crate) struct FakeRelease<'db> { - db: &'db TestDatabase, +pub(crate) struct FakeRelease<'a> { + db: &'a TestDatabase, package: MetadataPackage, build_result: BuildResult, /// name, content - source_files: Vec<(String, Vec)>, + source_files: Vec<(&'a str, &'a [u8])>, /// name, content - rustdoc_files: Vec<(String, Vec)>, + rustdoc_files: Vec<(&'a str, &'a [u8])>, doc_targets: Vec, default_target: Option, cratesio_data: CratesIoData, @@ -20,8 +20,8 @@ pub(crate) struct FakeRelease<'db> { has_examples: bool, } -impl<'db> FakeRelease<'db> { - pub(super) fn new(db: &'db TestDatabase) -> Self { +impl<'a> FakeRelease<'a> { + pub(super) fn new(db: &'a TestDatabase) -> Self { FakeRelease { db, package: MetadataPackage { @@ -85,28 +85,15 @@ impl<'db> FakeRelease<'db> { self } - pub(crate) fn file(mut self, mimetype: M, path: P, data: D) -> Self - where M: Into, - P: Into, - D: Into>, - { - let (mimetype, path, data) = (mimetype.into(), path.into(), data.into()); - self.files.push((mimetype, path, data)); - self - } - - pub(crate) fn rustdoc_file(mut self, path: P, data: D) -> Self - where P: Into, - D: Into>, - { - self.rustdoc_files.push((path.into(), data.into())); + pub(crate) fn rustdoc_file(mut self, path: &'a str, data: &'a [u8]) -> Self { + self.rustdoc_files.push((path, data)); self } pub(crate) fn create(self) -> Result { let tempdir = tempdir::TempDir::new("docs.rs-fake")?; - let upload_files = |prefix: &str, files: &[(String, Vec)]| { + let upload_files = |prefix: &str, files: &[(&str, &[u8])]| { let path_prefix = tempdir.path().join(prefix); std::fs::create_dir(&path_prefix)?; diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 3f202eebd..187dae3df 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -425,8 +425,8 @@ mod test { db.fake_release() .name("buggy").version("0.1.0") .build_result_successful(true) - .rustdoc_file("settings.html", "some data") - .rustdoc_file("all.html", "some data 2") + .rustdoc_file("settings.html", b"some data") + .rustdoc_file("all.html", b"some data 2") .create()?; db.fake_release() .name("buggy").version("0.2.0")