Skip to content

Commit

Permalink
add loop-test-server instructions and improve file handling in async …
Browse files Browse the repository at this point in the history
…functions

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Nov 14, 2024
1 parent 06bb7ed commit 6681a85
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
10 changes: 10 additions & 0 deletions maskfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,13 @@ PowerShell:
```powershell
[Diagnostics.Process]::Start(".\\tests\\fixtures\\rest_server\\rest-server.exe", "--path .\\tests\\generated\\test_storage\\ --htpasswd-file .\\tests\\fixtures\\test_data\\.htpasswd --log .\\tests\\fixtures\\rest_server\\response2.log").WaitForExit()
```

## loop-test-server

> Run our server for testing in a loop
PowerShell:

```powershell
watchexec --stop-signal "CTRL+C" -r -w src -- "cargo run -- serve -c tests/fixtures/test_data/rustic_server.toml -v"
```
3 changes: 3 additions & 0 deletions src/handlers/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(crate) async fn has_config(

if path_to_storage.exists() {
let file = storage.open_file(path, tpe.into_str(), None).await?;

let length = file
.metadata()
.await
Expand All @@ -60,7 +61,9 @@ pub(crate) async fn get_config<P: PathParts>(
range: Option<TypedHeader<Range>>,
) -> ApiResult<impl IntoResponse> {
let tpe = TpeKind::Config;

let repo = path.repo().unwrap();

tracing::debug!("[get_config] repository path: {repo}, tpe: {tpe}");

let _ = check_name(tpe, None)?;
Expand Down
11 changes: 10 additions & 1 deletion src/handlers/file_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ pub(crate) async fn file_length<P: PathParts>(
let (path, tpe, name) = path.parts();

tracing::debug!("[length] path: {path:?}, tpe: {tpe:?}, name: {name:?}");

let path_str = path.unwrap_or_default();

let path = Path::new(&path_str);

let _ = check_auth_and_acl(auth.user, tpe, path, AccessType::Read)?;

let tpe = if let Some(tpe) = tpe {
Expand All @@ -37,6 +40,7 @@ pub(crate) async fn file_length<P: PathParts>(

if file.exists() {
let storage = STORAGE.get().unwrap();

let file = storage
.open_file(path, tpe, name.as_deref())
.await
Expand Down Expand Up @@ -93,7 +97,9 @@ mod test {

let uri =
"/test_repo/keys/3f918b737a2b9f72f044d06d6009eb34e0e8d06668209be3ce86e5c18dac0295";

let request = request_uri_for_test(uri, Method::HEAD);

let resp = app.oneshot(request).await.unwrap();

assert_eq!(resp.status(), StatusCode::OK);
Expand All @@ -114,7 +120,7 @@ mod test {
.unwrap()
.to_bytes()
.to_vec();

assert!(b.is_empty());

// ----------------------------------
Expand All @@ -125,7 +131,9 @@ mod test {
.layer(middleware::from_fn(print_request_response));

let uri = "/test_repo/keys/__I_do_not_exist__";

let request = request_uri_for_test(uri, Method::HEAD);

let resp = app.oneshot(request).await.unwrap();

assert_eq!(resp.status(), StatusCode::NOT_FOUND);
Expand All @@ -137,6 +145,7 @@ mod test {
.unwrap()
.to_bytes()
.to_vec();

assert!(b.is_empty());
}
}
10 changes: 5 additions & 5 deletions tests/endpoints.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ HTTP 200
Content-Type: application/vnd.x.restic.rest.v1

GET http://127.0.0.1:8000/ci_repo/keys/92c489eaca950f3a9d860da1bef0af845dd8c74a9a34c860bd8e6a54bd2326d2
RANGE: bytes=0-460
RANGE: bytes=0-230
[BasicAuth]
restic: restic
HTTP 206

GET http://127.0.0.1:8000/ci_repo/keys/92c489eaca950f3a9d860da1bef0af845dd8c74a9a34c860bd8e6a54bd2326d2
[BasicAuth]
restic: restic
HTTP 200
# GET http://127.0.0.1:8000/ci_repo/keys/92c489eaca950f3a9d860da1bef0af845dd8c74a9a34c860bd8e6a54bd2326d2
# [BasicAuth]
# restic: restic
# HTTP 200

0 comments on commit 6681a85

Please sign in to comment.