From 8fbb3e11022243d06b08b8794345668790628ebf Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 12 Nov 2024 23:13:30 +0000 Subject: [PATCH] [spr] changes to main this commit is based on Created using spr 1.3.6-beta.1 [skip ci] --- .../api_trait.rs} | 0 .../mod.rs => integration-tests/common.rs} | 0 .../config.rs} | 55 ++++++++++++++++++- .../demo.rs} | 4 +- .../detached_shutdown.rs} | 2 +- dropshot/tests/integration-tests/main.rs | 25 +++++++++ .../multipart.rs} | 4 +- .../openapi.rs} | 0 .../pagination.rs} | 9 +-- .../pagination_schema.rs} | 0 .../path_names.rs} | 0 .../starter.rs} | 6 +- .../streaming.rs} | 4 +- .../{test_tls.rs => integration-tests/tls.rs} | 5 +- 14 files changed, 91 insertions(+), 23 deletions(-) rename dropshot/tests/{test_api_trait.rs => integration-tests/api_trait.rs} (100%) rename dropshot/tests/{common/mod.rs => integration-tests/common.rs} (100%) rename dropshot/tests/{test_config.rs => integration-tests/config.rs} (93%) rename dropshot/tests/{test_demo.rs => integration-tests/demo.rs} (99%) rename dropshot/tests/{test_detached_shutdown.rs => integration-tests/detached_shutdown.rs} (99%) create mode 100644 dropshot/tests/integration-tests/main.rs rename dropshot/tests/{test_multipart.rs => integration-tests/multipart.rs} (99%) rename dropshot/tests/{test_openapi.rs => integration-tests/openapi.rs} (100%) rename dropshot/tests/{test_pagination.rs => integration-tests/pagination.rs} (99%) rename dropshot/tests/{test_pagination_schema.rs => integration-tests/pagination_schema.rs} (100%) rename dropshot/tests/{test_path_names.rs => integration-tests/path_names.rs} (100%) rename dropshot/tests/{test_starter.rs => integration-tests/starter.rs} (98%) rename dropshot/tests/{test_streaming.rs => integration-tests/streaming.rs} (99%) rename dropshot/tests/{test_tls.rs => integration-tests/tls.rs} (99%) diff --git a/dropshot/tests/test_api_trait.rs b/dropshot/tests/integration-tests/api_trait.rs similarity index 100% rename from dropshot/tests/test_api_trait.rs rename to dropshot/tests/integration-tests/api_trait.rs diff --git a/dropshot/tests/common/mod.rs b/dropshot/tests/integration-tests/common.rs similarity index 100% rename from dropshot/tests/common/mod.rs rename to dropshot/tests/integration-tests/common.rs diff --git a/dropshot/tests/test_config.rs b/dropshot/tests/integration-tests/config.rs similarity index 93% rename from dropshot/tests/test_config.rs rename to dropshot/tests/integration-tests/config.rs index f2b71d7b9..b555e5efc 100644 --- a/dropshot/tests/test_config.rs +++ b/dropshot/tests/integration-tests/config.rs @@ -16,8 +16,59 @@ use std::sync::atomic::{AtomicU16, Ordering}; use tempfile::NamedTempFile; use tokio::sync::mpsc; -pub mod common; -use common::create_log_context; +use crate::common::{self, create_log_context}; + +#[test] +fn test_valid_config_empty() { + let parsed = + read_config::("valid_config_empty", "").unwrap(); + assert_eq!(parsed, ConfigDropshot::default()); +} + +#[test] +fn test_valid_config_basic() { + // Ensure that a basic config which leaves optional fields unset is + // correctly parsed. + let parsed = read_config::( + "valid_config_basic", + r#" + bind_address = "127.0.0.1:12345" + "#, + ) + .unwrap(); + + assert_eq!( + parsed, + ConfigDropshot { + bind_address: "127.0.0.1:12345".parse().unwrap(), + ..ConfigDropshot::default() + } + ); +} + +#[test] +fn test_valid_config_all_settings() { + let parsed = read_config::( + "valid_config_basic", + r#" + bind_address = "127.0.0.1:12345" + request_body_max_bytes = 1048576 + default_handler_task_mode = "cancel-on-disconnect" + log_headers = ["X-Forwarded-For"] + "#, + ) + .unwrap(); + + assert_eq!( + parsed, + ConfigDropshot { + bind_address: "127.0.0.1:12345".parse().unwrap(), + request_body_max_bytes: 1048576, + default_handler_task_mode: HandlerTaskMode::CancelOnDisconnect, + log_headers: vec!["X-Forwarded-For".to_string()], + }, + ); +} // Bad values for "bind_address" diff --git a/dropshot/tests/test_demo.rs b/dropshot/tests/integration-tests/demo.rs similarity index 99% rename from dropshot/tests/test_demo.rs rename to dropshot/tests/integration-tests/demo.rs index 6d26d047e..4c692c1c7 100644 --- a/dropshot/tests/test_demo.rs +++ b/dropshot/tests/integration-tests/demo.rs @@ -58,9 +58,9 @@ use tokio_tungstenite::tungstenite::Message; use tokio_tungstenite::WebSocketStream; use uuid::Uuid; -extern crate slog; +use crate::common; -pub mod common; +extern crate slog; fn demo_api() -> ApiDescription { let mut api = ApiDescription::::new(); diff --git a/dropshot/tests/test_detached_shutdown.rs b/dropshot/tests/integration-tests/detached_shutdown.rs similarity index 99% rename from dropshot/tests/test_detached_shutdown.rs rename to dropshot/tests/integration-tests/detached_shutdown.rs index 2c11f7fbe..edfa66825 100644 --- a/dropshot/tests/test_detached_shutdown.rs +++ b/dropshot/tests/integration-tests/detached_shutdown.rs @@ -11,7 +11,7 @@ use http::{Method, Response, StatusCode}; use std::time::Duration; use tokio::sync::mpsc; -pub mod common; +use crate::common; struct Context { endpoint_started_tx: mpsc::UnboundedSender<()>, diff --git a/dropshot/tests/integration-tests/main.rs b/dropshot/tests/integration-tests/main.rs new file mode 100644 index 000000000..b9f6468c5 --- /dev/null +++ b/dropshot/tests/integration-tests/main.rs @@ -0,0 +1,25 @@ +// Copyright 2024 Oxide Computer Company + +//! Integration tests for Dropshot. +//! +//! These are all combined into the same file to ensure that a single binary is +//! generated, speeding up link times. + +#[macro_use] +extern crate slog; +#[macro_use] +extern crate lazy_static; + +mod api_trait; +mod common; +mod config; +mod demo; +mod detached_shutdown; +mod multipart; +mod openapi; +mod pagination; +mod pagination_schema; +mod path_names; +mod starter; +mod streaming; +mod tls; diff --git a/dropshot/tests/test_multipart.rs b/dropshot/tests/integration-tests/multipart.rs similarity index 99% rename from dropshot/tests/test_multipart.rs rename to dropshot/tests/integration-tests/multipart.rs index 3728ce501..2ec40734e 100644 --- a/dropshot/tests/test_multipart.rs +++ b/dropshot/tests/integration-tests/multipart.rs @@ -8,9 +8,9 @@ use dropshot::{ }; use http::{Method, Response, StatusCode}; -extern crate slog; +use crate::common; -pub mod common; +extern crate slog; fn api() -> ApiDescription { let mut api = ApiDescription::new(); diff --git a/dropshot/tests/test_openapi.rs b/dropshot/tests/integration-tests/openapi.rs similarity index 100% rename from dropshot/tests/test_openapi.rs rename to dropshot/tests/integration-tests/openapi.rs diff --git a/dropshot/tests/test_pagination.rs b/dropshot/tests/integration-tests/pagination.rs similarity index 99% rename from dropshot/tests/test_pagination.rs rename to dropshot/tests/integration-tests/pagination.rs index 51d3d3ab0..3e443fa70 100644 --- a/dropshot/tests/test_pagination.rs +++ b/dropshot/tests/integration-tests/pagination.rs @@ -46,12 +46,7 @@ use subprocess::NullFile; use subprocess::Popen; use uuid::Uuid; -#[macro_use] -extern crate slog; -#[macro_use] -extern crate lazy_static; - -pub mod common; +use crate::common; // Common helpers @@ -571,7 +566,7 @@ lazy_static! { } fn make_word_list() -> BTreeSet { - let word_list = include_str!("wordlist.txt"); + let word_list = include_str!("../wordlist.txt"); word_list.lines().map(|s| s.to_string()).collect() } diff --git a/dropshot/tests/test_pagination_schema.rs b/dropshot/tests/integration-tests/pagination_schema.rs similarity index 100% rename from dropshot/tests/test_pagination_schema.rs rename to dropshot/tests/integration-tests/pagination_schema.rs diff --git a/dropshot/tests/test_path_names.rs b/dropshot/tests/integration-tests/path_names.rs similarity index 100% rename from dropshot/tests/test_path_names.rs rename to dropshot/tests/integration-tests/path_names.rs diff --git a/dropshot/tests/test_starter.rs b/dropshot/tests/integration-tests/starter.rs similarity index 98% rename from dropshot/tests/test_starter.rs rename to dropshot/tests/integration-tests/starter.rs index bb90ef522..a1fa4b0c9 100644 --- a/dropshot/tests/test_starter.rs +++ b/dropshot/tests/integration-tests/starter.rs @@ -3,9 +3,6 @@ //! Quick check that the "legacy" HttpServerStarter::new() and //! HttpServerStarter::new_with_tls() interfaces work. -pub mod common; - -use common::create_log_context; use dropshot::endpoint; use dropshot::test_util::read_json; use dropshot::test_util::ClientTestContext; @@ -17,6 +14,9 @@ use dropshot::HttpResponseOk; use dropshot::HttpServerStarter; use dropshot::RequestContext; +use crate::common; +use crate::common::create_log_context; + extern crate slog; /// Test starting a server with `HttpServerStarter::new()`. diff --git a/dropshot/tests/test_streaming.rs b/dropshot/tests/integration-tests/streaming.rs similarity index 99% rename from dropshot/tests/test_streaming.rs rename to dropshot/tests/integration-tests/streaming.rs index fffa51bef..718fd8f2e 100644 --- a/dropshot/tests/test_streaming.rs +++ b/dropshot/tests/integration-tests/streaming.rs @@ -8,9 +8,9 @@ use http::{Method, Response, StatusCode}; use http_body_util::BodyExt; use tokio::io::{AsyncSeekExt, AsyncWriteExt}; -extern crate slog; +use crate::common; -pub mod common; +extern crate slog; fn api() -> ApiDescription { let mut api = ApiDescription::new(); diff --git a/dropshot/tests/test_tls.rs b/dropshot/tests/integration-tests/tls.rs similarity index 99% rename from dropshot/tests/test_tls.rs rename to dropshot/tests/integration-tests/tls.rs index 9ac700ca9..d6c27bfc4 100644 --- a/dropshot/tests/test_tls.rs +++ b/dropshot/tests/integration-tests/tls.rs @@ -13,10 +13,7 @@ use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; -pub mod common; -use common::create_log_context; - -use crate::common::generate_tls_key; +use crate::common::{self, create_log_context, generate_tls_key}; /// See rustls::client::ServerCertVerifier::verify_server_cert for argument /// meanings