iron / iron-test Goto Github PK
View Code? Open in Web Editor NEWUtilities for testing Iron and Iron Middleware
Utilities for testing Iron and Iron Middleware
I'd like to reuse response in such code:
// .. cut
let body = response::extract_body_to_string(resp);
assert_eq!(body, "expected-content");
assert_eq!(resp.status.unwrap(), Status::Created);
// ..
Is it possible now?
Now it gives:
|
93 | let body = response::extract_body_to_string(resp);
| ---- value moved here
...
96 | assert_eq!(resp.status.unwrap(), Status::Created);
| ^^^^^^^^^^^ value used here after move
|
= note: move occurs because `resp` has type `iron::Response`, which does not implement the `Copy` trait
How would we feel about a request API that makes the request for you, broken down by HTTP method?
Something like:
mod request {
pub fn get<H: Handler>(url: &str, handler: H) -> Response
pub fn post<H: Handler>(url: &str, handler: H, data: Vec<u8>) -> Response
// etc
}
It's a little more syntactic sugar than the previously outlined constructor API, but it would also DRY up end user's tests a bit more, and remove some duplicated setup patterns.
I'd being willing to implement either API, just thought of this while I was using this library to test an Iron project.
Hi, iron 0.5.x has been released. https://github.com/iron/iron/releases
Would you update the dependency?
Is there an example of how to test with router
? (https://crates.io/crates/router)
I tried to get route information in handlers like so:
let route_info = req.extensions.get::<Router>().unwrap();
But in the test request
it will fail (return None
so unwrap
panic)
Currently it's not easily possible to quickly setup a project structure to test against.
For example, to test static_file
middleware, I need to make sure that there is a certain directory layout with specific files in it which could be served.
We should build a set of helpers to simplify this (similar to what Cargo does).
The code may look like:
test!(serves_specific_non_default_file {
let st = Static::new(Path::new(""));
// mock request and give it to handle method
// verify response
})
the test!
macro will call the setup
function and then call the actual test code.
The setup function will be defined once per tests module and will create a directory layout:
project("foo").file("index.html", "<html>hello</html>").build();
I'm currently adapting cargo testing support infrastructure to be used in iron_test.
I actually finished it today, but there was a bug in the code which rm-rf'ed '.' and all my code is gone, I'll need to recreate it tomorrow :)
Executing cargo test
with the provided example does not work.
$ cargo test โฑ
Compiling hello-world v0.0.1 (file:///Users/willweiss/dev/rust/hello-world)
src/main.rs:21:64: 21:70 error: no method named `unwrap` found for type `iron::Response` in the current scope
src/main.rs:21 let result_body = response::extract_body_to_bytes(response.unwrap());
^~~~~~
error: aborting due to previous error
error: Could not compile `hello-world`.
Changing the test to read:
#[test]
fn test_hello_world() {
let res = request::get("http://localhost:3000/hello",
Headers::new(),
&HelloWorldHandler).unwrap();
let result_body = response::extract_body_to_bytes(res);
assert_eq!(result_body, b"Hello, world!");
}
Fixes the issue as iron_test::response::extract_body_to_bytes
takes an argument of type iron::response::Response
per the docs.
Thanks in advance!
darwin 14.5.0
cargo 0.10.0-nightly (10ddd7d 2016-04-08)
iron 0.3.0
iron-test 0.3.0
Just wanted to start off by saying I love Iron and all the associated projects, I think they're great ๐
I've got a couple quick questions about this repo, just to make sure I'm going insane.
The README show mock requests being built like request::new(<http_method>, <request_target>)
, while the actual request::new()
function looks like it needs three arguments, the third being a reader.
The other functions shown, request::at
, request::at_with
and all of response
, don't seem to exist at all.
So I just wanted to confirm, is this project 'unfinished' at the moment? Or am I entirely missing something?
Once again, thank you for all the work ๐
Feature request: setting request headers is a bit cumbersome right now, it would be nice if the request::* functions took a Modifier instead of a Headers.
Please consider moving the project to iron organization.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.