mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 05:25:00 +02:00
implement conditional put/patch
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -64,3 +64,48 @@ pub async fn head_known_with_jsonpatch() -> eyre::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tanu::test]
|
||||
pub async fn head_conditional() -> eyre::Result<()> {
|
||||
let key = random_key();
|
||||
let text = random_text(1024);
|
||||
|
||||
let http = Client::new();
|
||||
|
||||
let res = http.key_put(&key).body(text.clone()).send().await?;
|
||||
check!(res.status().is_success());
|
||||
|
||||
let res = http.key_head(&key).send().await?;
|
||||
check!(res.status().is_success());
|
||||
let etag = res.header("etag").expect("ETag not found");
|
||||
|
||||
// Test without If-None-Match (normal GET)
|
||||
let res = http.key_head(&key).send().await?;
|
||||
check!(res.status().is_success());
|
||||
|
||||
// Test with If-None-Match: *
|
||||
let res = http
|
||||
.key_head(&key)
|
||||
.header("If-None-Match", "*")
|
||||
.send()
|
||||
.await?;
|
||||
check_eq!(res.status(), http::StatusCode::NOT_MODIFIED);
|
||||
|
||||
// Test with correct ETag
|
||||
let res = http
|
||||
.key_head(&key)
|
||||
.header("If-None-Match", etag)
|
||||
.send()
|
||||
.await?;
|
||||
check_eq!(res.status(), http::StatusCode::NOT_MODIFIED);
|
||||
|
||||
// Test with incorrect ETag
|
||||
let res = http
|
||||
.key_head(&key)
|
||||
.header("If-None-Match", "\"invalid-etag\"")
|
||||
.send()
|
||||
.await?;
|
||||
check!(res.status().is_success());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user