Skip to content

Start with CI #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
language: rust

sudo: required

before_install:
- wget https://dl.influxdata.com/influxdb/releases/influxdb_1.7.6_amd64.deb
- sudo dpkg -i influxdb_1.7.6_amd64.deb
- sudo influxd > $HOME/influx.log 2>&1 &

branches:
only:
- master

cache:
directories:
- /home/travis/.cargo

before_cache:
- rm -rf /home/travis/.cargo/registry

env:
os:
- linux
rust:
- stable
- beta
- nightly

matrix:
fast_finish: true
allow_failures:
include:
- rust: stable
env: NAME='linting'
before_script:
- rustup component add rustfmt-preview
- rustup component add clippy-preview
script:
- cargo fmt --all -- --check
- cargo clippy

- env: NAME='cargo-travis'
sudo: required
before_script:
- cargo install cargo-update || echo "cargo-update already installed"
- cargo install cargo-travis || echo "cargo-travis already installed"
- cargo install-update -a
script:
- |
cargo build &&
cargo coverage &&
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make &&
sudo make install && cd ../.. &&
kcov --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/influxdb-*
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- binutils-dev
- cmake

script: |
export RUST_BACKTRACE=1 &&
cargo build &&
cargo test &&
cargo doc --no-deps
49 changes: 21 additions & 28 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,7 @@ impl InfluxDbClient {
{
use futures::future;

let query_type = q.get_type();
let endpoint = match query_type {
QueryType::ReadQuery => "query",
QueryType::WriteQuery => "write",
};

let q_type = q.get_type();
let query = match q.build() {
Err(err) => {
let error = InfluxDbError::InvalidQueryError {
Expand All @@ -136,34 +131,32 @@ impl InfluxDbClient {
Ok(query) => query,
};

let query_str = query.get();
let url_params = match query_type {
QueryType::ReadQuery => format!("&q={}", query_str),
QueryType::WriteQuery => String::from(""),
};

let client = match query_type {
QueryType::ReadQuery => Client::new().get(
format!(
"{url}/{endpoint}?db={db}{url_params}",
url = self.url,
endpoint = endpoint,
db = self.database,
url_params = url_params
)
.as_str(),
),
let client = match q_type {
QueryType::ReadQuery => {
let read_query = query.get();
let http_query_string = format!(
"{url}/query?db={db}&q={read_query}",
url = self.database_url(),
db = self.database_name(),
read_query = read_query,
);

if read_query.contains("SELECT") || read_query.contains("SHOW") {
Client::new().get(http_query_string.as_str())
} else {
Client::new().post(http_query_string.as_str())
}
}
QueryType::WriteQuery => Client::new()
.post(
format!(
"{url}/{endpoint}?db={db}",
url = self.url,
endpoint = endpoint,
db = self.database,
"{url}/write?db={db}",
url = self.database_url(),
db = self.database_name(),
)
.as_str(),
)
.body(query_str),
.body(query.get()),
};

Box::new(
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub enum InfluxDbError {
#[fail(display = "InfluxDB encountered the following error: {}", error)]
/// Error which has happened inside InfluxDB
DatabaseError { error: String },
}
}
43 changes: 18 additions & 25 deletions src/integrations/serde_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ impl InfluxDbClient {
{
use futures::future;

let query_type = q.get_type();
let endpoint = match query_type {
QueryType::ReadQuery => "query",
QueryType::WriteQuery => "write",
};

let q_type = q.get_type();
let query = match q.build() {
Err(err) => {
let error = InfluxDbError::InvalidQueryError {
Expand All @@ -105,34 +100,32 @@ impl InfluxDbClient {
Ok(query) => query,
};

let query_str = query.get();
let url_params = match query_type {
QueryType::ReadQuery => format!("&q={}", query_str),
QueryType::WriteQuery => String::from(""),
};

let client = match query_type {
QueryType::ReadQuery => Client::new().get(
format!(
"{url}/{endpoint}?db={db}{url_params}",
let client = match q_type {
QueryType::ReadQuery => {
let read_query = query.get();
let http_query_string = format!(
"{url}/query?db={db}&q={read_query}",
url = self.database_url(),
endpoint = endpoint,
db = self.database_name(),
url_params = url_params
)
.as_str(),
),
read_query = read_query,
);

if read_query.contains("SELECT") || read_query.contains("SHOW") {
Client::new().get(http_query_string.as_str())
} else {
Client::new().post(http_query_string.as_str())
}
}
QueryType::WriteQuery => Client::new()
.post(
format!(
"{url}/{endpoint}?db={db}",
"{url}/write?db={db}",
url = self.database_url(),
endpoint = endpoint,
db = self.database_name(),
)
.as_str(),
)
.body(query_str),
.body(query.get()),
};

Box::new(
Expand Down Expand Up @@ -169,4 +162,4 @@ impl InfluxDbClient {
}),
)
}
}
}
5 changes: 3 additions & 2 deletions src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Used to create queries of type [`InfluxDbReadQuery`](crate::query::read_query::InfluxDbReadQuery) or [`InfluxDbWriteQuery`](crate::query::write_query::InfluxDbWriteQuery) which can be executed in InfluxDB
//! Used to create queries of type [`InfluxDbReadQuery`](crate::query::read_query::InfluxDbReadQuery) or
//! [`InfluxDbWriteQuery`](crate::query::write_query::InfluxDbWriteQuery) which can be executed in InfluxDB
//!
//! # Examples
//!
Expand Down Expand Up @@ -103,4 +104,4 @@ impl PartialEq<&str> for ValidQuery {
pub enum QueryType {
ReadQuery,
WriteQuery,
}
}
2 changes: 1 addition & 1 deletion src/query/read_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ impl InfluxDbQuery for InfluxDbReadQuery {
fn get_type(&self) -> QueryType {
QueryType::ReadQuery
}
}
}
2 changes: 1 addition & 1 deletion src/query/write_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ impl InfluxDbQuery for InfluxDbWriteQuery {
fn get_type(&self) -> QueryType {
QueryType::WriteQuery
}
}
}
29 changes: 26 additions & 3 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ fn test_ping_influx_db() {
println!("build: {} version: {}", build, version);
}

#[test]
/// INTEGRATION TEST
///
/// Tests if a database can be created
fn test_create_database() {
let client = create_client();
let query = InfluxDbQuery::raw_read_query("CREATE DATABASE test");
let result = get_runtime().block_on(client.query(query));
assert!(
result.is_ok(),
format!("Should be no error: {}", result.unwrap_err())
);
}

#[test]
/// INTEGRATION TEST
///
Expand All @@ -36,7 +50,10 @@ fn test_write_field() {
let client = create_client();
let query = InfluxDbQuery::write_query("weather").add_field("temperature", 82);
let result = get_runtime().block_on(client.query(query));
assert!(result.is_ok(), "Should be no error");
assert!(
result.is_ok(),
format!("Should be no error: {}", result.unwrap_err())
);
}

#[test]
Expand All @@ -47,7 +64,10 @@ fn test_read() {
let client = create_client();
let query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
let result = get_runtime().block_on(client.query(query));
assert!(result.is_ok(), "Should be no error");
assert!(
result.is_ok(),
format!("Should be no error: {}", result.unwrap_err())
);
assert!(
!result.unwrap().contains("error"),
"Data contained a database error"
Expand All @@ -72,5 +92,8 @@ fn test_json_query() {
let query = InfluxDbQuery::raw_read_query("SELECT * FROM weather");
let result = get_runtime().block_on(client.json_query::<Weather, _>(query));

assert!(result.is_ok(), "We could read from the DB");
assert!(
result.is_ok(),
format!("We couldn't read from the DB: {}", result.unwrap_err())
);
}