From 9f5ce664e9b42d42154ca5bb9ec2f8331d1b9e33 Mon Sep 17 00:00:00 2001 From: Rajat Jindal Date: Thu, 16 Nov 2023 17:51:29 +0530 Subject: [PATCH] remove unused functions Signed-off-by: Rajat Jindal --- crates/e2e-testing/src/controller.rs | 2 +- crates/e2e-testing/src/lib.rs | 2 +- crates/e2e-testing/src/metadata.rs | 28 ++++++ crates/e2e-testing/src/metadata_extractor.rs | 97 -------------------- crates/e2e-testing/src/spin_controller.rs | 2 +- crates/e2e-testing/src/testcase.rs | 2 +- tests/testcases/mod.rs | 2 +- 7 files changed, 33 insertions(+), 102 deletions(-) create mode 100644 crates/e2e-testing/src/metadata.rs delete mode 100644 crates/e2e-testing/src/metadata_extractor.rs diff --git a/crates/e2e-testing/src/controller.rs b/crates/e2e-testing/src/controller.rs index 9c46ccea88..0d136e7364 100644 --- a/crates/e2e-testing/src/controller.rs +++ b/crates/e2e-testing/src/controller.rs @@ -1,4 +1,4 @@ -use crate::metadata_extractor::AppMetadata; +use crate::metadata::AppMetadata; use anyhow::Result; use async_trait::async_trait; use std::process::Output; diff --git a/crates/e2e-testing/src/lib.rs b/crates/e2e-testing/src/lib.rs index 76dc8c8176..040dea8664 100644 --- a/crates/e2e-testing/src/lib.rs +++ b/crates/e2e-testing/src/lib.rs @@ -1,7 +1,7 @@ pub mod asserts; pub mod controller; pub mod http_asserts; -pub mod metadata_extractor; +pub mod metadata; pub mod spin; pub mod spin_controller; pub mod testcase; diff --git a/crates/e2e-testing/src/metadata.rs b/crates/e2e-testing/src/metadata.rs new file mode 100644 index 0000000000..5d2c18ff52 --- /dev/null +++ b/crates/e2e-testing/src/metadata.rs @@ -0,0 +1,28 @@ +use anyhow::Result; + +#[derive(Clone)] +pub struct AppRoute { + pub name: String, + pub route_url: String, + pub wildcard: bool, +} + +#[derive(Clone)] +pub struct AppMetadata { + pub name: String, + pub base: String, + pub app_routes: Vec, + pub version: String, +} + +impl AppMetadata { + pub fn get_route_with_name(&self, name: String) -> Result<&AppRoute> { + for route in &self.app_routes { + if route.name == name { + return Ok(route); + } + } + + Err("requested route not found").map_err(anyhow::Error::msg) + } +} diff --git a/crates/e2e-testing/src/metadata_extractor.rs b/crates/e2e-testing/src/metadata_extractor.rs deleted file mode 100644 index 670f87c8fe..0000000000 --- a/crates/e2e-testing/src/metadata_extractor.rs +++ /dev/null @@ -1,97 +0,0 @@ -use anyhow::Result; -use regex::Regex; -use url::Url; - -#[derive(Clone)] -pub struct AppRoute { - pub name: String, - pub route_url: String, - pub wildcard: bool, -} - -#[derive(Clone)] -pub struct AppMetadata { - pub name: String, - pub base: String, - pub app_routes: Vec, - pub version: String, -} - -impl AppMetadata { - pub fn get_route_with_name(&self, name: String) -> Result<&AppRoute> { - for route in &self.app_routes { - if route.name == name { - return Ok(route); - } - } - - Err("requested route not found").map_err(anyhow::Error::msg) - } -} - -/// Extracts version of app being deployed by parsing logs -pub fn extract_version_from_logs(appname: &str, logs: &str) -> String { - let re: Regex = Regex::new(format!("Uploading {} version (.*)...", appname).as_str()).unwrap(); - let v = match re.find(logs) { - None => "", - Some(v) => v.as_str(), - }; - - v.to_string() -} - -/// Extracts routes of app being deployed by parsing logs -pub fn extract_routes_from_logs(logs: &str) -> Vec { - let re: Regex = Regex::new(r"^\s*(.*): (https?://[^\s^\\(]+)(.*)$").unwrap(); - let mut route_start = false; - let lines = logs.split('\n'); - let mut routes: Vec = vec![]; - for line in lines { - if line.trim() == "" { - continue; - } - - if !route_start && line.trim() != "Available Routes:" { - continue; - } - - if !route_start { - route_start = true; - continue; - } - - let captures = re.captures(line).unwrap(); - - let route = AppRoute { - name: captures.get(1).unwrap().as_str().to_string(), - route_url: captures.get(2).unwrap().as_str().to_string(), - wildcard: captures.get(3).unwrap().as_str() == "(wildcard)", - }; - - routes.push(route) - } - - routes -} - -/// Extract metadata of app being deployed -/// -/// name, base url, version and available app routes are extracted from logs -pub fn extract_app_metadata_from_logs(appname: &str, logs: &str) -> AppMetadata { - let version = extract_version_from_logs(appname, logs); - let app_routes = extract_routes_from_logs(logs); - let mut base = "".to_string(); - if !app_routes.is_empty() { - base = match Url::parse(&app_routes.first().unwrap().route_url) { - Err(err) => panic!("{}", err), - Ok(url) => format!("{}://{}", url.scheme(), url.host().unwrap()), - } - } - - AppMetadata { - name: appname.to_string(), - base, - version, - app_routes, - } -} diff --git a/crates/e2e-testing/src/spin_controller.rs b/crates/e2e-testing/src/spin_controller.rs index 9e8e01f49a..919d021ebb 100644 --- a/crates/e2e-testing/src/spin_controller.rs +++ b/crates/e2e-testing/src/spin_controller.rs @@ -1,5 +1,5 @@ use crate::controller::{AppInstance, Controller, ExitedInstance}; -use crate::metadata_extractor::AppMetadata; +use crate::metadata::AppMetadata; use crate::spin; use crate::utils; use anyhow::{Context, Result}; diff --git a/crates/e2e-testing/src/testcase.rs b/crates/e2e-testing/src/testcase.rs index 776ed3b9b9..e50f1885cc 100644 --- a/crates/e2e-testing/src/testcase.rs +++ b/crates/e2e-testing/src/testcase.rs @@ -1,5 +1,5 @@ use crate::controller::Controller; -use crate::metadata_extractor::AppMetadata; +use crate::metadata::AppMetadata; use crate::spin; use crate::utils; use anyhow::{Context, Result}; diff --git a/tests/testcases/mod.rs b/tests/testcases/mod.rs index 121cf94fe6..d336ceeee3 100644 --- a/tests/testcases/mod.rs +++ b/tests/testcases/mod.rs @@ -1,7 +1,7 @@ use anyhow::Result; use e2e_testing::controller::Controller; use e2e_testing::http_asserts::assert_http_response; -use e2e_testing::metadata_extractor::AppMetadata; +use e2e_testing::metadata::AppMetadata; use e2e_testing::testcase::TestCaseBuilder; use e2e_testing::{spin, utils}; use hyper::Method;