Test a few API error codes
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Alex 2022-04-28 11:57:14 +02:00
parent 754919170f
commit 17883bbe4c
Signed by: lx
GPG key ID: 0E496D15096376BE
2 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,141 @@
use crate::common;
use hyper::Method;
#[tokio::test]
async fn test_error_codes() {
let ctx = common::context();
let bucket = ctx.create_bucket("test-k2v-error-codes");
// Regular insert should work (code 200)
let res = ctx
.k2v
.request
.builder(bucket.clone())
.method(Method::PUT)
.path("root")
.query_param("sort_key", Some("test1"))
.body(b"Hello, world!".to_vec())
.send()
.await
.unwrap();
assert_eq!(res.status(), 200);
// Insert with trash causality token: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.method(Method::PUT)
.path("root")
.query_param("sort_key", Some("test1"))
.signed_header("x-garage-causality-token", "tra$sh")
.body(b"Hello, world!".to_vec())
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Search without partition key: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{},
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Search with start that is not in prefix: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{"partition_key": "root", "prefix": "a", "start": "bx"},
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Search with invalid json: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{"partition_key": "root"
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Batch insert with invalid causality token: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.body(
br#"[
{"pk": "root", "sk": "a", "ct": "tra$h", "v": "aGVsbG8sIHdvcmxkCg=="}
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Batch insert with invalid data: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.body(
br#"[
{"pk": "root", "sk": "a", "ct": null, "v": "aGVsbG8sIHdvcmx$Cg=="}
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
// Poll with invalid causality token: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.path("root")
.query_param("sort_key", Some("test1"))
.query_param("causality_token", Some("tra$h"))
.query_param("timeout", Some("10"))
.signed_header("accept", "application/octet-stream")
.send()
.await
.unwrap();
assert_eq!(res.status(), 400);
}

View file

@ -1,4 +1,5 @@
pub mod batch; pub mod batch;
pub mod errorcodes;
pub mod item; pub mod item;
pub mod poll; pub mod poll;
pub mod simple; pub mod simple;