Skip to content

Commit e6f73a3

Browse files
committed
refactor!: remove htsget-lambda library code and replace with axum router
1 parent aa51483 commit e6f73a3

File tree

13 files changed

+152
-1090
lines changed

13 files changed

+152
-1090
lines changed

htsget-actix/src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,16 @@ mod tests {
175175
struct ActixTestRequest<T>(T);
176176

177177
impl TestRequest for ActixTestRequest<test::TestRequest> {
178-
fn insert_header(self, header: TestHeader<impl Into<String>>) -> Self {
179-
Self(self.0.insert_header(header.into_tuple()))
178+
fn insert_header(
179+
self,
180+
header: TestHeader<impl Into<http_1::HeaderName>, impl Into<http_1::HeaderValue>>,
181+
) -> Self {
182+
let (name, value) = header.into_tuple();
183+
Self(
184+
self
185+
.0
186+
.insert_header((name.to_string(), value.to_str().unwrap())),
187+
)
180188
}
181189

182190
fn set_payload(self, payload: impl Into<String>) -> Self {
@@ -187,11 +195,15 @@ mod tests {
187195
Self(self.0.uri(&uri.into()))
188196
}
189197

190-
fn method(self, method: impl Into<String>) -> Self {
198+
fn method(self, method: impl Into<http_1::Method>) -> Self {
191199
Self(
192-
self
193-
.0
194-
.method(method.into().parse().expect("expected valid method")),
200+
self.0.method(
201+
method
202+
.into()
203+
.to_string()
204+
.parse()
205+
.expect("expected valid method"),
206+
),
195207
)
196208
}
197209
}
@@ -224,7 +236,7 @@ mod tests {
224236
&self.config
225237
}
226238

227-
fn get_request(&self) -> ActixTestRequest<test::TestRequest> {
239+
fn request(&self) -> ActixTestRequest<test::TestRequest> {
228240
ActixTestRequest(test::TestRequest::default())
229241
}
230242

htsget-actix/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use htsget_config::command;
88

99
#[actix_web::main]
1010
async fn main() -> std::io::Result<()> {
11-
if let Some(path) =
12-
Config::parse_args_with_command(command!()).expect("expected valid command parsing")
13-
{
11+
if let Some(path) = Config::parse_args_with_command(command!())? {
1412
let config = Config::from_path(&path)?;
1513

1614
config.setup_tracing()?;

htsget-axum/src/server/data.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod tests {
8888

8989
use async_trait::async_trait;
9090
use http::header::HeaderName;
91-
use http::{HeaderMap, HeaderValue, Method};
91+
use http::{HeaderMap, Method};
9292
use reqwest::{Client, ClientBuilder, RequestBuilder};
9393
use tempfile::{tempdir, TempDir};
9494
use tokio::fs::{create_dir, File};
@@ -118,11 +118,11 @@ mod tests {
118118
}
119119

120120
impl TestRequest for DataTestRequest {
121-
fn insert_header(mut self, header: Header<impl Into<String>>) -> Self {
122-
self.headers.insert(
123-
HeaderName::from_str(&header.name.into()).unwrap(),
124-
HeaderValue::from_str(&header.value.into()).unwrap(),
125-
);
121+
fn insert_header(
122+
mut self,
123+
header: Header<impl Into<HeaderName>, impl Into<http::HeaderValue>>,
124+
) -> Self {
125+
self.headers.insert(header.name.into(), header.value.into());
126126
self
127127
}
128128

@@ -136,8 +136,8 @@ mod tests {
136136
self
137137
}
138138

139-
fn method(mut self, method: impl Into<String>) -> Self {
140-
self.method = method.into().parse().unwrap();
139+
fn method(mut self, method: impl Into<Method>) -> Self {
140+
self.method = method.into();
141141
self
142142
}
143143
}
@@ -186,7 +186,7 @@ mod tests {
186186
&self.config
187187
}
188188

189-
fn get_request(&self) -> DataTestRequest {
189+
fn request(&self) -> DataTestRequest {
190190
DataTestRequest::default()
191191
}
192192

@@ -294,8 +294,8 @@ mod tests {
294294

295295
let test_server = DataTestServer::default();
296296
let request = test_server
297-
.get_request()
298-
.method(Method::GET.to_string())
297+
.request()
298+
.method(Method::GET)
299299
.uri(format!("{scheme}://localhost:{port}/data/key1"));
300300
let response = test_server.test_server(request, "".to_string()).await;
301301

htsget-axum/src/server/ticket.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ mod tests {
105105
use std::convert::Infallible;
106106
use std::path::Path;
107107
use std::result;
108-
use std::str::FromStr;
109108

110109
use super::*;
111110
use async_trait::async_trait;
@@ -119,7 +118,7 @@ mod tests {
119118
TestRequest, TestServer,
120119
};
121120
use http::header::HeaderName;
122-
use http::Request;
121+
use http::{Method, Request};
123122
use tempfile::TempDir;
124123
use tower::ServiceExt;
125124

@@ -130,15 +129,14 @@ mod tests {
130129
struct AxumTestRequest<T>(T);
131130

132131
impl TestRequest for AxumTestRequest<Request<Body>> {
133-
fn insert_header(mut self, header: Header<impl Into<String>>) -> Self {
134-
self.0.headers_mut().insert(
135-
HeaderName::from_str(&header.name.into()).expect("expected valid header name"),
136-
header
137-
.value
138-
.into()
139-
.parse()
140-
.expect("expected valid header value"),
141-
);
132+
fn insert_header(
133+
mut self,
134+
header: Header<impl Into<HeaderName>, impl Into<http::HeaderValue>>,
135+
) -> Self {
136+
self
137+
.0
138+
.headers_mut()
139+
.insert(header.name.into(), header.value.into());
142140
self
143141
}
144142

@@ -153,8 +151,8 @@ mod tests {
153151
self
154152
}
155153

156-
fn method(mut self, method: impl Into<String>) -> Self {
157-
*self.0.method_mut() = method.into().parse().expect("expected valid method");
154+
fn method(mut self, method: impl Into<Method>) -> Self {
155+
*self.0.method_mut() = method.into();
158156
self
159157
}
160158
}
@@ -187,7 +185,7 @@ mod tests {
187185
&self.config
188186
}
189187

190-
fn get_request(&self) -> AxumTestRequest<Request<Body>> {
188+
fn request(&self) -> AxumTestRequest<Request<Body>> {
191189
AxumTestRequest(Request::default())
192190
}
193191

@@ -306,4 +304,9 @@ mod tests {
306304
async fn cors_preflight_request() {
307305
cors::test_cors_preflight_request(&AxumTestServer::default()).await;
308306
}
307+
308+
#[tokio::test]
309+
async fn get_route_invalid_method() {
310+
server::test_errors(&AxumTestServer::default()).await;
311+
}
309312
}

htsget-lambda/src/handlers/get.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

htsget-lambda/src/handlers/mod.rs

Lines changed: 0 additions & 140 deletions
This file was deleted.

htsget-lambda/src/handlers/post.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)