mirror of
https://github.com/actix/actix-extras.git
synced 2025-02-08 21:06:07 +01:00
add tests
This commit is contained in:
parent
5b9b8c6dd9
commit
118d0de8e6
67
.travis.yml
Normal file
67
.travis.yml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
language: rust
|
||||||
|
rust:
|
||||||
|
- 1.20.0
|
||||||
|
- stable
|
||||||
|
- beta
|
||||||
|
- nightly
|
||||||
|
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
|
services:
|
||||||
|
- redis-server
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- RUSTFLAGS="-C link-dead-code"
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- libcurl4-openssl-dev
|
||||||
|
- libelf-dev
|
||||||
|
- libdw-dev
|
||||||
|
- cmake
|
||||||
|
- gcc
|
||||||
|
- binutils-dev
|
||||||
|
- libiberty-dev
|
||||||
|
|
||||||
|
# Add clippy
|
||||||
|
before_script:
|
||||||
|
- |
|
||||||
|
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
|
||||||
|
( ( cargo install clippy && export CLIPPY=true ) || export CLIPPY=false );
|
||||||
|
fi
|
||||||
|
- export PATH=$PATH:~/.cargo/bin
|
||||||
|
|
||||||
|
script:
|
||||||
|
- |
|
||||||
|
if [[ "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
|
||||||
|
USE_SKEPTIC=1 cargo test
|
||||||
|
else
|
||||||
|
cargo test
|
||||||
|
cd examples/chat && cargo check && cd ../..
|
||||||
|
fi
|
||||||
|
- |
|
||||||
|
if [[ "$TRAVIS_RUST_VERSION" == "nightly" && $CLIPPY ]]; then
|
||||||
|
cargo clippy
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Upload docs
|
||||||
|
after_success:
|
||||||
|
- |
|
||||||
|
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
|
||||||
|
cargo doc --no-deps &&
|
||||||
|
echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
||||||
|
git clone https://github.com/davisp/ghp-import.git &&
|
||||||
|
./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc &&
|
||||||
|
echo "Uploaded documentation"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- |
|
||||||
|
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "nightly" ]]; then
|
||||||
|
bash <(curl https://raw.githubusercontent.com/xd009642/tarpaulin/master/travis-install.sh)
|
||||||
|
USE_SKEPTIC=1 cargo tarpaulin --out Xml
|
||||||
|
bash <(curl -s https://codecov.io/bash)
|
||||||
|
echo "Uploaded code coverage"
|
||||||
|
fi
|
@ -23,7 +23,7 @@ default = ["web"]
|
|||||||
web = ["actix-web", "cookie", "http", "rand", "serde", "serde_json"]
|
web = ["actix-web", "cookie", "http", "rand", "serde", "serde_json"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "^0.4.3"
|
actix = "^0.4.5"
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
backoff = "0.1"
|
backoff = "0.1"
|
||||||
|
@ -14,7 +14,7 @@ extern crate trust_dns_resolver;
|
|||||||
mod redis;
|
mod redis;
|
||||||
mod connect;
|
mod connect;
|
||||||
|
|
||||||
pub use redis::RedisActor;
|
pub use redis::{Command, RedisActor};
|
||||||
pub use connect::TcpConnector;
|
pub use connect::TcpConnector;
|
||||||
|
|
||||||
#[cfg(feature="web")]
|
#[cfg(feature="web")]
|
||||||
@ -56,3 +56,7 @@ impl From<redis_async::error::Error> for Error {
|
|||||||
Error::Redis(err)
|
Error::Redis(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// re-export
|
||||||
|
pub use redis_async::resp::RespValue;
|
||||||
|
pub use redis_async::error::Error as RespError;
|
||||||
|
@ -14,7 +14,7 @@ use redis_async::resp::{RespCodec, RespValue};
|
|||||||
use Error;
|
use Error;
|
||||||
use connect::TcpConnector;
|
use connect::TcpConnector;
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message, Debug)]
|
||||||
#[rtype(RespValue, Error)]
|
#[rtype(RespValue, Error)]
|
||||||
pub struct Command(pub RespValue);
|
pub struct Command(pub RespValue);
|
||||||
|
|
||||||
|
68
tests/test_redis.rs
Normal file
68
tests/test_redis.rs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
extern crate actix;
|
||||||
|
extern crate actix_redis;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate redis_async;
|
||||||
|
extern crate futures;
|
||||||
|
extern crate env_logger;
|
||||||
|
|
||||||
|
use actix::prelude::*;
|
||||||
|
use actix_redis::{RedisActor, Command, Error, RespValue};
|
||||||
|
use futures::Future;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_error_connect() {
|
||||||
|
let sys = System::new("test");
|
||||||
|
|
||||||
|
let addr = RedisActor::start("localhost:54000");
|
||||||
|
let _addr2 = addr.clone();
|
||||||
|
|
||||||
|
Arbiter::handle().spawn_fn(move || {
|
||||||
|
addr.call_fut(Command(resp_array!["GET", "test"]))
|
||||||
|
.then(|res| {
|
||||||
|
match res {
|
||||||
|
Ok(Err(Error::NotConnected)) => (),
|
||||||
|
_ => panic!("Should not happen {:?}", res),
|
||||||
|
}
|
||||||
|
Arbiter::system().send(actix::msgs::SystemExit(0));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
sys.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_redis() {
|
||||||
|
env_logger::init();
|
||||||
|
let sys = System::new("test");
|
||||||
|
|
||||||
|
let addr = RedisActor::start("127.0.0.1:6379");
|
||||||
|
let _addr2 = addr.clone();
|
||||||
|
|
||||||
|
Arbiter::handle().spawn_fn(move || {
|
||||||
|
let addr2 = addr.clone();
|
||||||
|
addr.call_fut(Command(resp_array!["SET", "test", "value"]))
|
||||||
|
.then(move |res| match res {
|
||||||
|
Ok(Ok(resp)) => {
|
||||||
|
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
|
||||||
|
addr2.call_fut(Command(resp_array!["GET", "test"]))
|
||||||
|
.then(|res| {
|
||||||
|
match res {
|
||||||
|
Ok(Ok(resp)) => {
|
||||||
|
println!("RESP: {:?}", resp);
|
||||||
|
assert_eq!(
|
||||||
|
resp, RespValue::BulkString((&b"value"[..]).into()));
|
||||||
|
},
|
||||||
|
_ => panic!("Should not happen {:?}", res),
|
||||||
|
}
|
||||||
|
Arbiter::system().send(actix::msgs::SystemExit(0));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_ => panic!("Should not happen {:?}", res),
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
sys.run();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user