-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy patherror.rs
78 lines (69 loc) · 2.5 KB
/
error.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
pub mod common;
use common::*;
use elasticsearch::ExplainParts;
use reqwest::StatusCode;
use serde_json::{json, Value};
/// Responses in the range 400-599 return Response body
#[tokio::test]
async fn bad_request_returns_response() -> anyhow::Result<()> {
let client = client::create_default();
let response = client
.explain(ExplainParts::IndexId("non_existent_index", "id"))
.body(json!({}))
.send()
.await?;
assert_eq!(response.status_code(), StatusCode::BAD_REQUEST);
let error = response.json::<Value>().await?;
assert_eq!(error["status"].as_i64(), Some(400));
assert_eq!(
error["error"]["type"].as_str(),
Some("action_request_validation_exception")
);
assert_eq!(
error["error"]["reason"].as_str(),
Some("Validation Failed: 1: query is missing;")
);
Ok(())
}
#[tokio::test]
async fn deserialize_exception() -> anyhow::Result<()> {
let client = client::create_default();
let response = client
.explain(ExplainParts::IndexId("non_existent_index", "id"))
.error_trace(true)
.body(json!({}))
.send()
.await?;
let status_code = response.status_code();
assert_eq!(status_code, StatusCode::BAD_REQUEST);
let ex = response.exception().await?.unwrap();
let error = ex.error();
assert_eq!(ex.status().unwrap(), status_code.as_u16());
assert_eq!(error.ty(), Some("action_request_validation_exception"));
assert!(error.stack_trace().is_some());
assert_eq!(
error.reason(),
Some("Validation Failed: 1: query is missing;")
);
assert!(!error.root_cause().is_empty());
assert_eq!(error.reason(), error.root_cause().first().unwrap().reason());
Ok(())
}