Skip to content

Commit 75429fd

Browse files
msrd0Empty2k12
authored andcommitted
Fix and Enforce Clippy Lints (#26)
1 parent 8cc4b32 commit 75429fd

File tree

6 files changed

+65
-135
lines changed

6 files changed

+65
-135
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ matrix:
4141
- rustup component add clippy-preview
4242
script:
4343
- cargo fmt --all -- --check
44-
- cargo clippy
44+
- cargo clippy --all-targets --all-features -- -D warnings
4545

4646
- env: NAME='cargo-travis'
4747
sudo: required

src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl InfluxDbClient {
104104
///
105105
/// let _client = InfluxDbClient::new("http://localhost:9086", "test").with_auth("admin", "password");
106106
/// ```
107-
pub fn with_auth<'a, S1, S2>(mut self, username: S1, password: S2) -> Self
107+
pub fn with_auth<S1, S2>(mut self, username: S1, password: S2) -> Self
108108
where
109109
S1: ToString,
110110
S2: ToString,

src/integrations/serde_integration.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ impl InfluxDbClient {
173173
.and_then(|body| {
174174
// Try parsing InfluxDBs { "error": "error message here" }
175175
if let Ok(error) = serde_json::from_slice::<_DatabaseError>(&body) {
176-
return futures::future::err(InfluxDbError::DatabaseError {
176+
futures::future::err(InfluxDbError::DatabaseError {
177177
error: error.error.to_string(),
178-
});
178+
})
179179
} else {
180180
// Json has another structure, let's try actually parsing it to the type we're deserializing
181181
let from_slice = serde_json::from_slice::<DatabaseQueryResult>(&body);
@@ -189,7 +189,7 @@ impl InfluxDbClient {
189189
}
190190
};
191191

192-
return futures::future::result(Ok(deserialized));
192+
futures::future::result(Ok(deserialized))
193193
}
194194
}),
195195
)

src/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ mod tests {
176176

177177
#[test]
178178
fn test_format_for_timestamp_now() {
179-
assert!(format!("{}", Timestamp::NOW) == String::from(""));
179+
assert!(format!("{}", Timestamp::NOW) == "");
180180
}
181181

182182
#[test]
183183
fn test_format_for_timestamp_else() {
184-
assert!(format!("{}", Timestamp::NANOSECONDS(100)) == String::from("100"));
184+
assert!(format!("{}", Timestamp::NANOSECONDS(100)) == "100");
185185
}
186186
}

src/query/read_query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl InfluxDbReadQuery {
2121
}
2222

2323
/// Adds a query to the [`InfluxDbReadQuery`]
24-
pub fn add<S>(mut self, query: S) -> Self
24+
pub fn add_query<S>(mut self, query: S) -> Self
2525
where
2626
S: ToString,
2727
{
@@ -54,7 +54,7 @@ mod tests {
5454
#[test]
5555
fn test_read_builder_multi_query() {
5656
let query = InfluxDbQuery::raw_read_query("SELECT * FROM aachen")
57-
.add("SELECT * FROM cologne")
57+
.add_query("SELECT * FROM cologne")
5858
.build();
5959

6060
assert_eq!(query.unwrap(), "SELECT * FROM aachen;SELECT * FROM cologne");

tests/integration_tests.rs

Lines changed: 56 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ use influxdb::error::InfluxDbError;
66
use influxdb::query::{InfluxDbQuery, Timestamp};
77
use tokio::runtime::current_thread::Runtime;
88

9+
fn assert_result_err<A: std::fmt::Debug, B: std::fmt::Debug>(result: &Result<A, B>) {
10+
result.as_ref().expect_err("assert_result_err failed");
11+
}
12+
13+
fn assert_result_ok<A: std::fmt::Debug, B: std::fmt::Debug>(result: &Result<A, B>) {
14+
result.as_ref().expect("assert_result_ok failed");
15+
}
16+
917
fn get_runtime() -> Runtime {
1018
Runtime::new().expect("Unable to create a runtime")
1119
}
@@ -50,11 +58,7 @@ where
5058
fn test_ping_influx_db() {
5159
let client = create_client("notusedhere");
5260
let result = get_runtime().block_on(client.ping());
53-
assert!(
54-
result.is_ok(),
55-
"Should be no error: {}",
56-
result.unwrap_err()
57-
);
61+
assert_result_ok(&result);
5862

5963
let (build, version) = result.unwrap();
6064
assert!(!build.is_empty(), "Build should not be empty");
@@ -73,19 +77,13 @@ fn test_connection_error() {
7377
.with_auth("nopriv_user", "password");
7478
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
7579
let read_result = get_runtime().block_on(client.query(&read_query));
76-
assert!(
77-
read_result.is_err(),
78-
format!("Should be an error: {}", read_result.unwrap_err())
79-
);
80+
assert_result_err(&read_result);
8081
match read_result {
81-
Err(InfluxDbError::ConnectionError { .. }) => assert!(true),
82-
_ => assert!(
83-
false,
84-
format!(
85-
"Should cause a ConnectionError: {}",
86-
read_result.unwrap_err()
87-
)
88-
),
82+
Err(InfluxDbError::ConnectionError { .. }) => {}
83+
_ => panic!(format!(
84+
"Should cause a ConnectionError: {}",
85+
read_result.unwrap_err()
86+
)),
8987
}
9088
}
9189

@@ -119,17 +117,11 @@ fn test_authed_write_and_read() {
119117
let write_query =
120118
InfluxDbQuery::write_query(Timestamp::HOURS(11), "weather").add_field("temperature", 82);
121119
let write_result = get_runtime().block_on(client.query(&write_query));
122-
assert!(
123-
write_result.is_ok(),
124-
format!("Should be no error: {}", write_result.unwrap_err())
125-
);
120+
assert_result_ok(&write_result);
126121

127122
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
128123
let read_result = get_runtime().block_on(client.query(&read_query));
129-
assert!(
130-
read_result.is_ok(),
131-
format!("Should be no error: {}", read_result.unwrap_err())
132-
);
124+
assert_result_ok(&read_result);
133125
assert!(
134126
!read_result.unwrap().contains("error"),
135127
"Data contained a database error"
@@ -166,55 +158,37 @@ fn test_wrong_authed_write_and_read() {
166158
let write_query =
167159
InfluxDbQuery::write_query(Timestamp::HOURS(11), "weather").add_field("temperature", 82);
168160
let write_result = get_runtime().block_on(client.query(&write_query));
169-
assert!(
170-
write_result.is_err(),
171-
format!("Should be an error: {}", write_result.unwrap_err())
172-
);
161+
assert_result_err(&write_result);
173162
match write_result {
174-
Err(InfluxDbError::AuthorizationError) => assert!(true),
175-
_ => assert!(
176-
false,
177-
format!(
178-
"Should be an AuthorizationError: {}",
179-
write_result.unwrap_err()
180-
)
181-
),
163+
Err(InfluxDbError::AuthorizationError) => {}
164+
_ => panic!(format!(
165+
"Should be an AuthorizationError: {}",
166+
write_result.unwrap_err()
167+
)),
182168
}
183169

184170
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
185171
let read_result = get_runtime().block_on(client.query(&read_query));
186-
assert!(
187-
read_result.is_err(),
188-
format!("Should be an error: {}", read_result.unwrap_err())
189-
);
172+
assert_result_err(&read_result);
190173
match read_result {
191-
Err(InfluxDbError::AuthorizationError) => assert!(true),
192-
_ => assert!(
193-
false,
194-
format!(
195-
"Should be an AuthorizationError: {}",
196-
read_result.unwrap_err()
197-
)
198-
),
174+
Err(InfluxDbError::AuthorizationError) => {}
175+
_ => panic!(format!(
176+
"Should be an AuthorizationError: {}",
177+
read_result.unwrap_err()
178+
)),
199179
}
200180

201181
let client = InfluxDbClient::new("http://localhost:9086", test_name)
202182
.with_auth("nopriv_user", "password");
203183
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
204184
let read_result = get_runtime().block_on(client.query(&read_query));
205-
assert!(
206-
read_result.is_err(),
207-
format!("Should be an error: {}", read_result.unwrap_err())
208-
);
185+
assert_result_err(&read_result);
209186
match read_result {
210-
Err(InfluxDbError::AuthenticationError) => assert!(true),
211-
_ => assert!(
212-
false,
213-
format!(
214-
"Should be an AuthenticationError: {}",
215-
read_result.unwrap_err()
216-
)
217-
),
187+
Err(InfluxDbError::AuthenticationError) => {}
188+
_ => panic!(format!(
189+
"Should be an AuthenticationError: {}",
190+
read_result.unwrap_err()
191+
)),
218192
}
219193
}
220194

@@ -246,36 +220,24 @@ fn test_non_authed_write_and_read() {
246220
let write_query =
247221
InfluxDbQuery::write_query(Timestamp::HOURS(11), "weather").add_field("temperature", 82);
248222
let write_result = get_runtime().block_on(non_authed_client.query(&write_query));
249-
assert!(
250-
write_result.is_err(),
251-
format!("Should be an error: {}", write_result.unwrap_err())
252-
);
223+
assert_result_err(&write_result);
253224
match write_result {
254-
Err(InfluxDbError::AuthorizationError) => assert!(true),
255-
_ => assert!(
256-
false,
257-
format!(
258-
"Should be an AuthorizationError: {}",
259-
write_result.unwrap_err()
260-
)
261-
),
225+
Err(InfluxDbError::AuthorizationError) => {}
226+
_ => panic!(format!(
227+
"Should be an AuthorizationError: {}",
228+
write_result.unwrap_err()
229+
)),
262230
}
263231

264232
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
265233
let read_result = get_runtime().block_on(non_authed_client.query(&read_query));
266-
assert!(
267-
read_result.is_err(),
268-
format!("Should be an error: {}", read_result.unwrap())
269-
);
234+
assert_result_err(&read_result);
270235
match read_result {
271-
Err(InfluxDbError::AuthorizationError) => assert!(true),
272-
_ => assert!(
273-
false,
274-
format!(
275-
"Should be an AuthorizationError: {}",
276-
read_result.unwrap_err()
277-
)
278-
),
236+
Err(InfluxDbError::AuthorizationError) => {}
237+
_ => panic!(format!(
238+
"Should be an AuthorizationError: {}",
239+
read_result.unwrap_err()
240+
)),
279241
}
280242
}
281243

@@ -296,17 +258,11 @@ fn test_write_and_read_field() {
296258
let write_query =
297259
InfluxDbQuery::write_query(Timestamp::HOURS(11), "weather").add_field("temperature", 82);
298260
let write_result = get_runtime().block_on(client.query(&write_query));
299-
assert!(
300-
write_result.is_ok(),
301-
format!("Should be no error: {}", write_result.unwrap_err())
302-
);
261+
assert_result_ok(&write_result);
303262

304263
let read_query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
305264
let read_result = get_runtime().block_on(client.query(&read_query));
306-
assert!(
307-
read_result.is_ok(),
308-
format!("Should be no error: {}", read_result.unwrap_err())
309-
);
265+
assert_result_ok(&read_result);
310266
assert!(
311267
!read_result.unwrap().contains("error"),
312268
"Data contained a database error"
@@ -338,10 +294,7 @@ fn test_json_query() {
338294
let write_query =
339295
InfluxDbQuery::write_query(Timestamp::HOURS(11), "weather").add_field("temperature", 82);
340296
let write_result = get_runtime().block_on(client.query(&write_query));
341-
assert!(
342-
write_result.is_ok(),
343-
format!("Should be no error: {}", write_result.unwrap_err())
344-
);
297+
assert_result_ok(&write_result);
345298

346299
#[derive(Deserialize, Debug, PartialEq)]
347300
struct Weather {
@@ -354,11 +307,7 @@ fn test_json_query() {
354307
.json_query(query)
355308
.and_then(|mut db_result| db_result.deserialize_next::<Weather>());
356309
let result = get_runtime().block_on(future);
357-
358-
assert!(
359-
result.is_ok(),
360-
format!("We couldn't read from the DB: {}", result.unwrap_err())
361-
);
310+
assert_result_ok(&result);
362311

363312
assert_eq!(
364313
result.unwrap().series[0].values[0],
@@ -411,12 +360,7 @@ fn test_json_query_vec() {
411360
.json_query(query)
412361
.and_then(|mut db_result| db_result.deserialize_next::<Weather>());
413362
let result = get_runtime().block_on(future);
414-
415-
assert!(
416-
result.is_ok(),
417-
format!("We couldn't read from the DB: {}", result.unwrap_err())
418-
);
419-
363+
assert_result_ok(&result);
420364
assert_eq!(result.unwrap().series[0].values.len(), 3);
421365

422366
delete_db(test_name).expect("could not clean up db");
@@ -458,21 +402,13 @@ fn test_serde_multi_query() {
458402

459403
let write_result = get_runtime().block_on(client.query(&write_query));
460404
let write_result2 = get_runtime().block_on(client.query(&write_query2));
461-
462-
assert!(
463-
write_result.is_ok(),
464-
format!("Write Query 1 failed: {}", write_result.unwrap_err())
465-
);
466-
467-
assert!(
468-
write_result2.is_ok(),
469-
format!("Write Query 2 failed: {}", write_result2.unwrap_err())
470-
);
405+
assert_result_ok(&write_result);
406+
assert_result_ok(&write_result2);
471407

472408
let future = client
473409
.json_query(
474410
InfluxDbQuery::raw_read_query("SELECT * FROM temperature")
475-
.add("SELECT * FROM humidity"),
411+
.add_query("SELECT * FROM humidity"),
476412
)
477413
.and_then(|mut db_result| {
478414
let temp = db_result.deserialize_next::<Temperature>();
@@ -481,22 +417,16 @@ fn test_serde_multi_query() {
481417
(temp, humidity)
482418
});
483419
let result = get_runtime().block_on(future);
484-
485-
assert!(
486-
result.is_ok(),
487-
format!("No problems should be had: {}", result.unwrap_err())
488-
);
420+
assert_result_ok(&result);
489421

490422
let (temp, humidity) = result.unwrap();
491-
492423
assert_eq!(
493424
temp.series[0].values[0],
494425
Temperature {
495426
time: "1970-01-01T11:00:00Z".to_string(),
496427
temperature: 16
497428
},
498429
);
499-
500430
assert_eq!(
501431
humidity.series[0].values[0],
502432
Humidity {

0 commit comments

Comments
 (0)