mirror of
https://github.com/samsonjs/agate.git
synced 2026-03-25 09:05:50 +00:00
add test framework and a basic test
This commit is contained in:
parent
be2d6f9f00
commit
f6ba98aa24
15 changed files with 359 additions and 0 deletions
170
Cargo.lock
generated
170
Cargo.lock
generated
|
|
@ -4,8 +4,11 @@
|
|||
name = "agate"
|
||||
version = "2.5.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"configparser",
|
||||
"env_logger",
|
||||
"gemini-fetch",
|
||||
"getopts",
|
||||
"glob",
|
||||
"log",
|
||||
|
|
@ -18,6 +21,26 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2475b58cd94eb4f70159f4fd8844ba3b807532fe3131b3373fae060bbe30396"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
"predicates",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
|
|
@ -41,12 +64,29 @@ version = "0.13.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.0.1"
|
||||
|
|
@ -71,6 +111,18 @@ version = "2.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2616d8c1fbf887d76dd8e067ec1bc3be7669994378428b4415a8e4ad57baae1"
|
||||
|
||||
[[package]]
|
||||
name = "difference"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.8.3"
|
||||
|
|
@ -93,6 +145,23 @@ dependencies = [
|
|||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gemini-fetch"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/Johann150/gemini-fetch.git#e1d3c57d874c96e7236500b4dac5127cfe9ebf53"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ring",
|
||||
"rustls",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"url",
|
||||
"webpki",
|
||||
"webpki-roots",
|
||||
"x509-signature",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.21"
|
||||
|
|
@ -252,6 +321,32 @@ version = "0.2.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa"
|
||||
dependencies = [
|
||||
"difference",
|
||||
"predicates-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"treeline",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
|
|
@ -270,6 +365,15 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.16.20"
|
||||
|
|
@ -345,6 +449,26 @@ dependencies = [
|
|||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.1.1"
|
||||
|
|
@ -373,6 +497,18 @@ dependencies = [
|
|||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"tokio-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-macros"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -386,6 +522,12 @@ dependencies = [
|
|||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "treeline"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
|
|
@ -449,6 +591,15 @@ version = "0.9.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.70"
|
||||
|
|
@ -523,6 +674,15 @@ dependencies = [
|
|||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.21.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
|
@ -553,3 +713,13 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "x509-signature"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fb2bc2a902d992cd5f471ee3ab0ffd6603047a4207384562755b9d6de977518"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"untrusted",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ url = "2.2.1"
|
|||
glob = "0.3"
|
||||
configparser = "2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "1.0"
|
||||
gemini-fetch = { git = "https://github.com/Johann150/gemini-fetch.git" }
|
||||
anyhow = "1.0"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
|
|
|
|||
29
tests/data/cert.pem
Normal file
29
tests/data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gwpeZXl5x7Knw8i4STDMB8GA1UdIwQY
|
||||
MBaAFI7IjwaA0gwpeZXl5x7Knw8i4STDMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZI
|
||||
hvcNAQELBQADggIBANQJ+WuQ8UZsk86t7jTS9K2Igit22ImXhdddDHHbBrbdLXoN
|
||||
g4IXij8mEJqfPyqZhT49S23booihvJOyhT/RgRB6LI/hBuV1vTwARmIRU4WhZAh0
|
||||
xIwVCqniDp6Rgf6OEOYgLGk11CEv7vMfPZYbLddDY1HvmSl8l087CLEQ37WRb51M
|
||||
5Quhsrny441s6aTn8I7c9WY2H/CUmlF8byoLuIl2MpR5bQN17binfsJZPYkKaMyJ
|
||||
5URM0nCVUEr+o/1znYsQJYa+GSVEsJJ6OyS7TMSoFJlVFslOxbdPzNkdcL6jxpXN
|
||||
B0rCrC1gTaQynxTOoQ56N8Z74V9xoXNd0ZwaSgEWfeM++YOyk3qgfvhobd0F8rTD
|
||||
8+dvMN7eI+N8P+S+VCnX9YzrQIZyTwEhHK9fXLlcqoiAhpizgGhlGctiZ1MmpzT2
|
||||
aqFmLOCKpcQLyofsSLSFbhV2/w8rJbS1kTlrzwQLzaJvtLVy+ZZdQFP49Vj8Lb7n
|
||||
3Oos/YeNoGhJoTWX7S2nQBChYMsSUA15+IS7RN0b+cJroHESsqCkbp07M20zhztz
|
||||
fDWdYFh+o4V2lF9ecnqV7MwTvz9WxpchcUfQgENrJ3dgTn35hsZOMM2anwFWrmG+
|
||||
KVyFMhWNnZB1E530Nsu9cNHntqc3sFBdJebrFED9gOFErt5Vou8btjIqPm/Y
|
||||
-----END CERTIFICATE-----
|
||||
12
tests/data/content/.meta
Normal file
12
tests/data/content/.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# test setting a mime type
|
||||
index.gmi: text/gemini
|
||||
# test globs and setting parameters
|
||||
*.de.gmi: ;lang=de
|
||||
# test double star globs
|
||||
**/*.nl.gmi: ;lang=nl
|
||||
# test setting multiple parameters
|
||||
test.gmi: ;lang=en ;charset=us-ascii
|
||||
# test setting data for nonexistent files
|
||||
gone.txt: 52 This file is no longer available.
|
||||
# test setting data for files in other directories
|
||||
example.com/index.gmi: ;lang=en-US
|
||||
2
tests/data/content/example.com/index.gmi
Normal file
2
tests/data/content/example.com/index.gmi
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This is example.com.
|
||||
=> gemini://example.org
|
||||
2
tests/data/content/example.org/index.gmi
Normal file
2
tests/data/content/example.org/index.gmi
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This is example.org.
|
||||
=> gemini://example.com/
|
||||
1
tests/data/content/index.gmi
Normal file
1
tests/data/content/index.gmi
Normal file
|
|
@ -0,0 +1 @@
|
|||
This is a test index file.
|
||||
0
tests/data/content/test.de.gmi
Normal file
0
tests/data/content/test.de.gmi
Normal file
2
tests/data/content/test.gmi
Normal file
2
tests/data/content/test.gmi
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
This is a test in the root
|
||||
Suppe
|
||||
2
tests/data/content/testdir/.meta
Normal file
2
tests/data/content/testdir/.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# test distributed configurations
|
||||
index.gmi: 51 No index file for you.
|
||||
0
tests/data/content/testdir/a.de.gmi
Normal file
0
tests/data/content/testdir/a.de.gmi
Normal file
0
tests/data/content/testdir/a.gmi
Normal file
0
tests/data/content/testdir/a.gmi
Normal file
0
tests/data/content/testdir/a.nl.gmi
Normal file
0
tests/data/content/testdir/a.nl.gmi
Normal file
52
tests/data/key.rsa
Normal file
52
tests/data/key.rsa
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
-----BEGIN PRIVATE KEY-----
|
||||
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQD7f6oYIWWsoyrI
|
||||
KXu47tAn4gtnH3izCVzFo7VWjamVq7+ssWSw1Ob0R5PmR+i+ATxQhfK7BBZk6jE6
|
||||
i5pffS3dJS3WqEza0nD5uSA34zTYtJeLrsBu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KV8m9na8pPG+ZJd518oK8nuk9UMgwsJnCWEVgzVjzRIxv7AElrO
|
||||
tPwNvAOh6tUMmDlbRt+xdpFmU238jA==
|
||||
-----END PRIVATE KEY-----
|
||||
82
tests/tests.rs
Normal file
82
tests/tests.rs
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
use gemini_fetch::{Header, Page, Status};
|
||||
use std::io::Read;
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
use std::process::{Command, Stdio};
|
||||
use url::Url;
|
||||
|
||||
static BINARY_PATH: &'static str = env!("CARGO_BIN_EXE_agate");
|
||||
|
||||
fn addr() -> SocketAddr {
|
||||
"[::1]:1965".to_socket_addrs().unwrap().next().unwrap()
|
||||
}
|
||||
|
||||
fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
|
||||
// start the server
|
||||
let mut server = Command::new(BINARY_PATH)
|
||||
.stderr(Stdio::piped())
|
||||
.current_dir(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data"))
|
||||
.args(args)
|
||||
.spawn()
|
||||
.expect("failed to start binary");
|
||||
|
||||
// the first output is when Agate is listening, so we only have to wait
|
||||
// until the first byte is output
|
||||
let mut buffer = [0; 1];
|
||||
server
|
||||
.stderr
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.read_exact(&mut buffer)
|
||||
.unwrap();
|
||||
|
||||
// actually perform the request
|
||||
let page = tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async { Page::fetch_from(&Url::parse(url).unwrap(), addr(), None).await });
|
||||
|
||||
// try to stop the server again
|
||||
match server.try_wait() {
|
||||
Err(e) => panic!("cannot access orchestrated program: {:?}", e),
|
||||
// everything fine, still running as expected, kill it now
|
||||
Ok(None) => server.kill().unwrap(),
|
||||
Ok(Some(_)) => {
|
||||
// forward stderr so we have a chance to understand the problem
|
||||
let buffer = std::iter::once(Ok(buffer[0]))
|
||||
.chain(server.stderr.take().unwrap().bytes())
|
||||
.collect::<Result<Vec<u8>, _>>()
|
||||
.unwrap();
|
||||
|
||||
eprintln!("{}", String::from_utf8_lossy(&buffer));
|
||||
// make the test fail
|
||||
panic!("program had crashed");
|
||||
}
|
||||
}
|
||||
|
||||
page
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_page() {
|
||||
let page = get(&[], "gemini://localhost").expect("could not get page");
|
||||
|
||||
assert_eq!(
|
||||
page.header,
|
||||
Header {
|
||||
status: Status::Success,
|
||||
meta: "text/gemini".to_string(),
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
page.body,
|
||||
Some(
|
||||
std::fs::read_to_string(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/tests/data/content/index.gmi"
|
||||
))
|
||||
.unwrap()
|
||||
)
|
||||
);
|
||||
|
||||
println!("{:?}", page);
|
||||
}
|
||||
Loading…
Reference in a new issue