aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-11-13 15:38:19 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-11-13 15:38:19 -0800
commitc7ff87bc03d98c7fa8b2354223ae33f0fab8b5bd (patch)
treeb418dff0e671de87550ec63b3df10692bbc36b08
parentd14e86155fc0ae718954871f7adb59e415d98602 (diff)
downloadfatcat-c7ff87bc03d98c7fa8b2354223ae33f0fab8b5bd.tar.gz
fatcat-c7ff87bc03d98c7fa8b2354223ae33f0fab8b5bd.zip
start using client in some tests
-rw-r--r--rust/TODO4
-rw-r--r--rust/tests/test_api_server_client.rs57
-rw-r--r--rust/tests/test_api_server_http.rs (renamed from rust/tests/test_api_server.rs)8
3 files changed, 69 insertions, 0 deletions
diff --git a/rust/TODO b/rust/TODO
index c8a1a1bd..59722cd8 100644
--- a/rust/TODO
+++ b/rust/TODO
@@ -19,6 +19,10 @@ account helper tool
- test/validate tokens
later:
+- tried using sync::Once to wrap test database initilization (so it would only
+ run migrations once), but it didn't seem to work, maybe I had a bug or it
+ didn't compile?
+ => could also do a global mutex: https://github.com/SergioBenitez/Rocket/issues/697
- could some of the EntityCrud trait macro stuff be re-implemented as an enum type?
- pure-rust "benchmark" scripts that hit, eg, lookups and batch endpoints
=> criterion.rs benchmarking
diff --git a/rust/tests/test_api_server_client.rs b/rust/tests/test_api_server_client.rs
new file mode 100644
index 00000000..381dc6ab
--- /dev/null
+++ b/rust/tests/test_api_server_client.rs
@@ -0,0 +1,57 @@
+/*
+ * This file contains API server tests that hit the API through the Rust API client library.
+ *
+ * These tests are relatively complex and mutate database state. Tests should take care not to be
+ * racey or overwrite each other; for example, they should randomize external identifiers and
+ * minimize reliance on hard-coded example entities.
+ *
+ * Note that these tests currently do *not* include tests the authentication system, or any other
+ * middleware.
+ */
+
+extern crate fatcat;
+extern crate fatcat_api_spec;
+extern crate uuid;
+extern crate iron;
+
+use iron::{Iron, Listening};
+use fatcat_api_spec::{Context, Api, ApiNoContext, Future, ContextWrapperExt};
+use fatcat_api_spec::client::Client;
+//use uuid::Uuid;
+
+
+fn setup() -> (
+ Context,
+ Client,
+ Listening,
+) {
+ let server = fatcat::test_server().unwrap();
+ let router = fatcat_api_spec::router(server);
+ let iron_server = Iron::new(router)
+ .http("localhost:9144")
+ .expect("Failed to start HTTP server");
+
+ let context = Context::new();
+ let client = Client::try_new_http("http://localhost:9144").unwrap();
+ (context, client, iron_server)
+}
+
+#[test]
+fn test_basic() {
+
+ let (context, client, mut server) = setup();
+ let client = client.with_context(context);
+
+ client.get_changelog_entry(1).wait().unwrap();
+ server.close().unwrap()
+}
+
+#[test]
+fn test_basic2() {
+
+ let (context, client, mut server) = setup();
+ let client = client.with_context(context);
+
+ client.get_changelog_entry(1).wait().unwrap();
+ server.close().unwrap()
+}
diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server_http.rs
index ebc74b67..26535bea 100644
--- a/rust/tests/test_api_server.rs
+++ b/rust/tests/test_api_server_http.rs
@@ -1,3 +1,11 @@
+/*
+ * This file contains API server tests that hit the API by connecting via the Iron client,
+ * essentially doing raw HTTP/JSON requests.
+ *
+ * These tests are relatively simple and don't mutate much database state; they are primarily to
+ * test basic serialization/deserialization, and take advantage of hard-coded example entities.
+ */
+
extern crate diesel;
extern crate fatcat;
extern crate fatcat_api_spec;