Skip to content
Snippets Groups Projects
Unverified Commit ada3652f authored by Louis's avatar Louis :fire:
Browse files

Add tests for content type and index files, include 'interpolate_idents' to generate test names

parent 6e20f818
No related branches found
No related tags found
No related merge requests found
......@@ -235,6 +235,11 @@ dependencies = [
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "interpolate_idents"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "isatty"
version = "0.1.7"
......@@ -639,6 +644,7 @@ dependencies = [
"docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"formdata 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
"interpolate_idents 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rhai 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -858,6 +864,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum httparse 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2f407128745b78abc95c0ffbe4e5d37427fdc0d45470710cfef8c44522a2e37"
"checksum hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)" = "368cb56b2740ebf4230520e2b90ebb0461e69034d85d1945febd9b3971426db2"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum interpolate_idents 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c038526b1556151b78f71b3e4cb107cf58c4dfc426a64a398c61f76a42a4e08"
"checksum isatty 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a118a53ba42790ef25c82bb481ecf36e2da892646cccd361e69a6bb881e19398"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
......
......@@ -37,3 +37,6 @@ hyper = "0.10"
rand = "0.3"
rhai = "0.7"
serde_yaml = "0.7.3"
[dev-dependencies]
interpolate_idents = "0.2.4"
example/files/adorable-puppy.jpg

73 KiB

file,author/attribution, link
adorable-puppy.jpg,Photo by mentatdgt from Pexels,https://www.pexels.com/photo/white-brown-and-black-shih-tzu-puppy-936317/
math.aswm,Github: Hanks10100,https://github.com/Hanks10100/wasm-examples
File added
......@@ -3,10 +3,11 @@
<head>
<meta charset="UTF-8">
<title>Swerve Example</title>
<link rel="stylesheet" href="/css/styles.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>It's Swervin' Time</h1>
<p>This page is part of the swerve example, and includes a stylesheet and stuff.</p>
<script async src="js/say_hello.js"></script>
</body>
</html>
\ No newline at end of file
document.addEventListener('DOMContentLoaded', function() {
console.log("The dom has loaded!")
})
\ No newline at end of file
extern crate rocket;
extern crate swerve;
use swerve::cli::{Args, SwerveConfig};
use swerve::server::create_server;
use rocket::local::Client;
use rocket::http::Status;
const INDEX_PAGE: &'static str = include_str!("../example/index.html");
#[test]
fn test_serves_index() {
let args = Args {
flag_dir: Some(String::from("example")),
..Args::default()
};
let config = SwerveConfig::default();
let server = create_server(args, config);
let client = Client::new(server).expect("valid server instance");
let mut response = client.get("/").dispatch();
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.body_string(), Some(INDEX_PAGE.into()));
}
\ No newline at end of file
#![feature(plugin)]
#![plugin(interpolate_idents)]
extern crate rocket;
extern crate swerve;
use swerve::cli::{Args, SwerveConfig};
use swerve::server::create_server;
use rocket::local::Client;
use rocket::http::ContentType;
macro_rules! test_type {
($name:ident, $path:expr, $content_path:expr) => (interpolate_idents! {
#[test]
fn [returns_some_type_for_ $name]() {
let args = Args {
flag_dir: Some(String::from("example")),
flag_quiet: true,
..Args::default()
};
let config = SwerveConfig::default();
let server = create_server(args, config);
let client = Client::new(server).expect("valid server instance");
let response = client.get($path).dispatch();
assert_eq!(response.content_type(), Some($content_path));
}
});
($name:ident, $path:expr) => (interpolate_idents! {
#[test]
fn [returns_no_type_for_ $name]() {
let args = Args {
flag_dir: Some(String::from("example")),
flag_quiet: true,
..Args::default()
};
let config = SwerveConfig::default();
let server = create_server(args, config);
let client = Client::new(server).expect("valid server instance");
let response = client.get($path).dispatch();
assert_eq!(response.content_type(), None);
}
});
}
test_type!(html, "/index.html", ContentType::HTML);
test_type!(css, "/css/styles.css", ContentType::CSS);
test_type!(javascript, "/js/say_hello.js", ContentType::JavaScript);
test_type!(csv, "/files/attribution.csv", ContentType::CSV);
test_type!(image_jpeg, "/files/adorable-puppy.jpg", ContentType::JPEG);
test_type!(web_assembly, "/files/math.wasm", ContentType::new("application", "wasm"));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment