Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.

Commit

Permalink
enable coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
ubnt-intrepid committed Oct 1, 2018
1 parent 26ca902 commit eeaf5a7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,28 @@ matrix:

include:
- rust: stable
sudo: required
addons:
apt:
packages:
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- binutils-dev
before_script:
- rustup component add rustfmt-preview
- cargo install cargo-update || true
- cargo install cargo-kcov || true
- cargo install-update -a
- export CARGO_INCREMENTAL=0
script:
- cargo update
- cargo test --all-features
- cargo fmt -- --check
- if [[ "${TRAVIS_PULL_REQUEST_BRANCH:-}" = release-* ]]; then cargo package; fi
after_success:
- cargo kcov --print-install-kcov-sh | sh
- cargo kcov -v --coveralls

- rust: beta
before_script:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![crates.io](https://img.shields.io/crates/v/finchers-session.svg)](https://crates.io/crates/finchers-session)
[![API documentation](https://img.shields.io/badge/api-docs-blue.svg)](https://finchers-rs.github.io/docs)
[![Build Status](https://travis-ci.org/finchers-rs/finchers-session.svg?branch=master)](https://travis-ci.org/finchers-rs/finchers-session)
[![Coverage Status](https://coveralls.io/repos/github/finchers-rs/finchers-session/badge.svg?branch=master)](https://coveralls.io/github/finchers-rs/finchers-session?branch=master)

Session support for Finchers.

Expand Down
12 changes: 8 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern crate pretty_env_logger;
extern crate serde;
extern crate serde_json;

use finchers::error::Error;
use finchers::prelude::*;

use http::Response;
Expand Down Expand Up @@ -39,15 +38,20 @@ fn main() {
let session = finchers_session::session(backend);

let endpoint = path!(@get /).and(session).and_then(|session: Session| {
session.with(|session| -> Result<_, Error> {
session.with(|session| {
// Retrieve the value of session.
//
// Note that the session value are stored as a UTF-8 string,
// which means that the user it is necessary for the user to
// deserialize/serialize the session data.
let mut session_value: SessionValue = {
let s = session.get().unwrap_or("");
serde_json::from_str(s).map_err(finchers::error::bad_request)?
let s = session.get().unwrap_or(r#"{ "text": "" }"#);
serde_json::from_str(s).map_err(|err| {
finchers::error::bad_request(format!(
"failed to parse session value (input = {:?}): {}",
s, err
))
})?
};

let response = Response::builder()
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ mod imp {
f: impl FnOnce(&mut Self) -> R,
) -> impl Future<Item = R::Item, Error = Error>
where
R: IntoFuture,
Error: From<R::Error>,
R: IntoFuture<Error = Error>,
{
f(&mut self)
.into_future()
.from_err()
.and_then(move |item| self.into_future().map(move |()| item))
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extern crate finchers;
extern crate finchers_session;

use finchers::local;
use finchers::prelude::*;
use finchers_session::backend::cookie;

type Session = finchers_session::Session<cookie::CookieSession>;

#[test]
fn test_no_op() {
let backend = cookie::plain();
let session = finchers_session::session(backend);

let endpoint = session.and_then(|session: Session| session.with(|_session| Ok("done")));

let response = local::get("/")
.header("host", "localhost:3000")
.respond(&endpoint);

assert!(!response.headers().contains_key("set-cookie"));
}

0 comments on commit eeaf5a7

Please sign in to comment.