-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathintegration_tests_v2.rs
127 lines (118 loc) · 4.14 KB
/
integration_tests_v2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
extern crate influxdb;
#[path = "./utilities.rs"]
mod utilities;
use utilities::{assert_result_err, assert_result_ok, run_test};
use influxdb::InfluxDbWriteable;
use influxdb::{Client, Error, ReadQuery, Timestamp};
/// INTEGRATION TEST
///
/// This test case tests the Authentication
#[async_std::test]
#[cfg(not(tarpaulin))]
async fn test_authed_write_and_read() {
run_test(
|| async move {
let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("admintoken");
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
let write_result = client.query(&write_query).await;
assert_result_ok(&write_result);
let read_query = ReadQuery::new("SELECT * FROM weather");
let read_result = client.query(read_query).await;
assert_result_ok(&read_result);
assert!(
!read_result.unwrap().contains("error"),
"Data contained a database error"
);
},
|| async move {
let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("admintoken");
let read_query = ReadQuery::new("DELETE MEASUREMENT weather");
let read_result = client.query(read_query).await;
assert_result_ok(&read_result);
assert!(!read_result.unwrap().contains("error"), "Teardown failed");
},
)
.await;
}
/// INTEGRATION TEST
///
/// This test case tests the Authentication
#[async_std::test]
#[cfg(not(tarpaulin))]
async fn test_wrong_authed_write_and_read() {
run_test(
|| async move {
let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("falsetoken");
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
let write_result = client.query(&write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
dbg!(code);
}
_ => panic!(
"Should be an AuthorizationError: {}",
write_result.unwrap_err()
),
}
let read_query = ReadQuery::new("SELECT * FROM weather");
let read_result = client.query(&read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
dbg!(code);
}
_ => panic!(
"Should be an AuthorizationError: {}",
read_result.unwrap_err()
),
}
},
|| async move {},
)
.await;
}
/// INTEGRATION TEST
///
/// This test case tests the Authentication
#[async_std::test]
#[cfg(not(tarpaulin))]
async fn test_non_authed_write_and_read() {
run_test(
|| async move {
let non_authed_client = Client::new("http://127.0.0.1:2086", "mydb");
let write_query = Timestamp::Hours(11)
.into_query("weather")
.add_field("temperature", 82);
let write_result = non_authed_client.query(&write_query).await;
assert_result_err(&write_result);
match write_result {
Err(Error::ApiError(code)) => {
dbg!(code);
}
_ => panic!(
"Should be an AuthorizationError: {}",
write_result.unwrap_err()
),
}
let read_query = ReadQuery::new("SELECT * FROM weather");
let read_result = non_authed_client.query(&read_query).await;
assert_result_err(&read_result);
match read_result {
Err(Error::ApiError(code)) => {
dbg!(code);
}
_ => panic!(
"Should be an AuthorizationError: {}",
read_result.unwrap_err()
),
}
},
|| async move {},
)
.await;
}