Merge test modules - cleanup.

This commit is contained in:
Tim Bruijnzeels
2020-03-16 14:55:21 -03:00
parent 67dcf3efb6
commit e755f0ab65
24 changed files with 116 additions and 114 deletions
+1 -1
View File
@@ -443,7 +443,7 @@ mod tests {
use super::*;
use crate::cli::options::KrillInitDetails;
use crate::commons::util::test;
use crate::test;
#[test]
fn init_config_file() {
+1 -1
View File
@@ -1910,7 +1910,7 @@ mod test {
use rpki::crypto::PublicKeyFormat;
use crate::commons::util::softsigner::OpenSslSigner;
use crate::commons::util::test;
use crate::test;
use super::*;
+1 -1
View File
@@ -35,7 +35,7 @@ mod tests {
use serde::Serialize;
use crate::commons::api::Handle;
use crate::commons::util::test;
use crate::test;
use super::*;
+1 -1
View File
@@ -782,7 +782,7 @@ mod tests {
use crate::commons::api::{
HexEncodedHash, ListElement, ListReply, Publish, PublishDeltaBuilder, Update, Withdraw,
};
use crate::commons::util::test::rsync;
use crate::test::rsync;
struct ListReplyBuilder {
elements: Vec<ListElement>,
+1 -1
View File
@@ -797,7 +797,7 @@ mod tests {
use rpki::x509::Time;
use crate::commons::remote::id::tests::test_id_certificate;
use crate::commons::util::test;
use crate::test;
use super::*;
+1 -2
View File
@@ -320,7 +320,7 @@ impl From<Error> for io::Error {
#[cfg(test)]
mod tests {
use crate::commons::util::test;
use crate::test;
use super::*;
@@ -357,5 +357,4 @@ mod tests {
assert!(files.contains(&file_4));
});
}
}
-1
View File
@@ -6,7 +6,6 @@ pub mod ext_serde;
pub mod file;
pub mod httpclient;
pub mod softsigner;
pub mod test;
pub mod xml;
pub fn sha256(object: &[u8]) -> Bytes {
+1 -1
View File
@@ -242,7 +242,7 @@ impl From<io::Error> for SignerError {
#[cfg(test)]
pub mod tests {
use crate::commons::util::test;
use crate::test;
use super::*;
-78
View File
@@ -1,78 +0,0 @@
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;
use bytes::Bytes;
use rand::{thread_rng, Rng};
use rpki::uri;
/// This method sets up a test directory with a random name (a number)
/// under 'work', relative to where cargo is running. It then runs the
/// test provided in the closure, and finally it cleans up the test
/// directory.
///
/// Note that if your test fails the directory is not cleaned up.
pub fn test_under_tmp<F>(op: F)
where
F: FnOnce(PathBuf) -> (),
{
let dir = sub_dir(&PathBuf::from("work"));
let path = PathBuf::from(&dir);
op(dir);
let _result = fs::remove_dir_all(path);
}
pub async fn test_under_tmp_async<F>(op: F)
where
F: FnOnce(PathBuf) -> (),
{
let dir = tmp_dir();
let path = PathBuf::from(&dir);
op(dir);
let _result = fs::remove_dir_all(path);
}
pub fn tmp_dir() -> PathBuf {
sub_dir(&PathBuf::from("work"))
}
/// This method sets up a random subdirectory and returns it. It is
/// assumed that the caller will clean this directory themselves.
pub fn sub_dir(base_dir: &PathBuf) -> PathBuf {
let mut rng = thread_rng();
let rnd: u32 = rng.gen();
let mut dir = base_dir.clone();
dir.push(PathBuf::from(format!("{}", rnd)));
let full_path = PathBuf::from(&dir);
fs::create_dir_all(&full_path).unwrap();
full_path
}
pub fn rsync(s: &str) -> uri::Rsync {
uri::Rsync::from_str(s).unwrap()
}
pub fn https(s: &str) -> uri::Https {
uri::Https::from_str(s).unwrap()
}
pub fn as_bytes(s: &str) -> Bytes {
Bytes::copy_from_slice(s.as_bytes())
}
pub fn save_file(base_dir: &PathBuf, file_name: &str, content: &[u8]) {
let mut full_name = base_dir.clone();
full_name.push(PathBuf::from(file_name));
let mut f = File::create(full_name).unwrap();
f.write_all(content).unwrap();
}
+1 -1
View File
@@ -1588,7 +1588,7 @@ impl<S: Signer> CertAuth<S> {
mod tests {
use super::*;
use crate::commons::util::softsigner::OpenSslSigner;
use crate::commons::util::test;
use crate::test;
#[test]
fn generate_id_cert() {
+1 -1
View File
@@ -1028,7 +1028,7 @@ mod tests {
use crate::commons::api::RepoInfo;
use crate::commons::util::softsigner::OpenSslSigner;
use crate::commons::util::test;
use crate::test;
#[test]
fn add_ta() {
+5 -3
View File
@@ -977,10 +977,12 @@ async fn refresh_all(req: Request) -> RoutingResult {
#[cfg(test)]
mod tests {
use super::*;
use crate::commons::util::test;
use std::path::PathBuf;
use crate::test;
use super::*;
#[tokio::test]
async fn start_tls_server() {
let dir = test::sub_dir(&PathBuf::from("work"));
@@ -993,6 +995,6 @@ mod tests {
tokio::spawn(super::start(server_conf));
assert!(crate::daemon::test::primary_server_ready().await);
assert!(test::primary_server_ready().await);
}
}
+1 -1
View File
@@ -300,7 +300,7 @@ impl std::error::Error for Error {}
#[cfg(test)]
mod tests {
// use actix_web::*;
use crate::commons::util::test;
use crate::test;
use super::*;
-1
View File
@@ -4,6 +4,5 @@ pub mod config;
pub mod http;
pub mod krillserver;
pub mod scheduler;
pub mod test;
mod mq;
+1
View File
@@ -33,3 +33,4 @@ pub mod constants;
pub mod daemon;
pub mod pubd;
pub mod publish;
pub mod test;
+1 -1
View File
@@ -278,8 +278,8 @@ mod tests {
use crate::commons::remote::builder::IdCertBuilder;
use crate::commons::remote::id::IdCert;
use crate::commons::util::file::CurrentFile;
use crate::commons::util::test;
use crate::pubd::Publisher;
use crate::test;
use super::*;
+82 -7
View File
@@ -1,11 +1,19 @@
//! Support for tests in other modules using a running krill server
//! Helper functions for testing Krill.
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;
use bytes::Bytes;
use rand::{thread_rng, Rng};
use hyper::StatusCode;
use tokio::time::{delay_for, timeout};
use rpki::uri;
use rpki::uri::Rsync;
use crate::cli::options::{BulkCaCommand, CaCommand, Command, Options, PublishersCommand};
@@ -19,8 +27,7 @@ use crate::commons::api::{
};
use crate::commons::remote::rfc8183;
use crate::commons::remote::rfc8183::ChildRequest;
use crate::commons::util::test::{sub_dir, tmp_dir};
use crate::commons::util::{httpclient, test};
use crate::commons::util::httpclient;
use crate::daemon::ca::ta_handle;
use crate::daemon::config::Config;
use crate::daemon::http::server;
@@ -76,7 +83,7 @@ pub async fn start_krill() -> PathBuf {
}
pub async fn start_secondary_krill(base_dir: &PathBuf) {
let data_dir = test::sub_dir(base_dir);
let data_dir = sub_dir(base_dir);
let server_conf = Config::pubd_test(&data_dir);
tokio::spawn(server::start(server_conf));
@@ -86,7 +93,7 @@ pub async fn start_secondary_krill(base_dir: &PathBuf) {
pub async fn krill_admin(command: Command) -> ApiResponse {
let krillc_opts = Options::new(
test::https("https://localhost:3000/"),
https("https://localhost:3000/"),
"secret",
ReportFormat::Json,
command,
@@ -99,7 +106,7 @@ pub async fn krill_admin(command: Command) -> ApiResponse {
pub async fn krill_admin_secondary(command: Command) -> ApiResponse {
let krillc_opts = Options::new(
test::https("https://localhost:3001/"),
https("https://localhost:3001/"),
"secret",
ReportFormat::Json,
command,
@@ -119,7 +126,7 @@ pub async fn krill_pubd_admin(command: Command, server: PubdTestContext) -> ApiR
pub async fn krill_admin_expect_error(command: Command) -> Error {
let krillc_opts = Options::new(
test::https("https://localhost:3000/"),
https("https://localhost:3000/"),
"secret",
ReportFormat::Json,
command,
@@ -440,3 +447,71 @@ pub async fn will_publish_objects(publisher: &PublisherHandle, objects: &[&str])
false
}
/// This method sets up a test directory with a random name (a number)
/// under 'work', relative to where cargo is running. It then runs the
/// test provided in the closure, and finally it cleans up the test
/// directory.
///
/// Note that if your test fails the directory is not cleaned up.
pub fn test_under_tmp<F>(op: F)
where
F: FnOnce(PathBuf) -> (),
{
let dir = sub_dir(&PathBuf::from("work"));
let path = PathBuf::from(&dir);
op(dir);
let _result = fs::remove_dir_all(path);
}
pub async fn test_under_tmp_async<F>(op: F)
where
F: FnOnce(PathBuf) -> (),
{
let dir = tmp_dir();
let path = PathBuf::from(&dir);
op(dir);
let _result = fs::remove_dir_all(path);
}
pub fn tmp_dir() -> PathBuf {
sub_dir(&PathBuf::from("work"))
}
/// This method sets up a random subdirectory and returns it. It is
/// assumed that the caller will clean this directory themselves.
pub fn sub_dir(base_dir: &PathBuf) -> PathBuf {
let mut rng = thread_rng();
let rnd: u32 = rng.gen();
let mut dir = base_dir.clone();
dir.push(PathBuf::from(format!("{}", rnd)));
let full_path = PathBuf::from(&dir);
fs::create_dir_all(&full_path).unwrap();
full_path
}
pub fn rsync(s: &str) -> uri::Rsync {
uri::Rsync::from_str(s).unwrap()
}
pub fn https(s: &str) -> uri::Https {
uri::Https::from_str(s).unwrap()
}
pub fn as_bytes(s: &str) -> Bytes {
Bytes::copy_from_slice(s.as_bytes())
}
pub fn save_file(base_dir: &PathBuf, file_name: &str, content: &[u8]) {
let mut full_name = base_dir.clone();
full_name.push(PathBuf::from(file_name));
let mut f = File::create(full_name).unwrap();
f.write_all(content).unwrap();
}
+3 -2
View File
@@ -1,9 +1,10 @@
extern crate krill;
use std::fs;
use krill::commons::api::{Handle, ParentCaReq, ResourceSet};
use krill::daemon::ca::ta_handle;
use krill::daemon::test::*;
use std::fs;
use krill::test::*;
#[tokio::test]
async fn ca_embedded() {
+3 -2
View File
@@ -1,9 +1,10 @@
extern crate krill;
use std::fs;
use krill::commons::api::{Handle, ObjectName, ParentCaReq, ResourceClassName, ResourceSet};
use krill::daemon::ca::ta_handle;
use krill::daemon::test::*;
use std::fs;
use krill::test::*;
#[tokio::test]
/// Test that we can delegate from normal CAs to child CAs, and that these child CAs
+3 -2
View File
@@ -1,9 +1,10 @@
extern crate krill;
use std::fs;
use krill::commons::api::{Handle, ParentCaReq, ResourceSet};
use krill::daemon::ca::ta_handle;
use krill::daemon::test::*;
use std::fs;
use krill::test::*;
#[tokio::test]
async fn ca_keyroll_rfc6492() {
+3 -2
View File
@@ -1,9 +1,10 @@
extern crate krill;
use std::fs;
use krill::commons::api::{Handle, ParentCaReq, ResourceSet};
use krill::daemon::ca::ta_handle;
use krill::daemon::test::*;
use std::fs;
use krill::test::*;
#[tokio::test]
async fn ca_rfc6492() {
+2 -2
View File
@@ -1,13 +1,13 @@
extern crate krill;
use std::fs;
use std::str::FromStr;
use krill::commons::api::{
Handle, ObjectName, ParentCaReq, ResourceSet, RoaDefinition, RoaDefinitionUpdates,
};
use krill::daemon::ca::ta_handle;
use krill::daemon::test::*;
use std::fs;
use krill::test::*;
#[tokio::test]
/// Test the CAs can issue and publish ROAs for their resources, and that
+1 -1
View File
@@ -19,7 +19,7 @@ use krill::commons::api::{
};
use krill::commons::remote::rfc8183;
use krill::daemon::ca::ta_handle;
use krill::daemon::test::{
use krill::test::{
add_child_to_ta_embedded, add_parent_to_ca, ca_gets_resources, ca_route_authorizations_update,
init_child_with_embedded_repo, krill_admin, krill_pubd_admin, start_krill,
start_secondary_krill, PubdTestContext,
+2 -1
View File
@@ -1,12 +1,13 @@
extern crate krill;
use std::path::PathBuf;
use krill::commons::api::Handle;
use krill::commons::eventsourcing::{AggregateStore, DiskAggregateStore};
use krill::commons::util::softsigner::OpenSslSigner;
use krill::constants::PUBSERVER_DFLT;
use krill::daemon::ca::CertAuth;
use krill::pubd::Repository;
use std::path::PathBuf;
/// This tests that we can understand all events as they have been implemented since 0.4.0,
/// in order to guarantee that upgrades will work.