testing: Move tests to specific directory Tests I didn't really write until today, as I mostly didn't really know how to set it up. This is now partially mitigated, just by forcing myself to do it. There's a few problems still in the code; the database is shared with the dev application for instance. Though as a start I'll take it.

zj
Oct 8, 2021, 11:49 AM
XFXPVFOSMN7MJKQS7B4HZ7USA4PNITW2XBS46IW75SG4XUOYMCSQC

Dependencies

  • [2] E4OBIIUB templates: Fix navigation mocks Cleans up the directory structure for templates and fixes the navigation bugs in the applications too. Includes a context! macro which is lifted from upstream, but is currently unreleased. When rocket_dyn_templates is updates, it could be DRY'ed out.
  • [3] KULVODXD routes: User route mod exposes routes() now Other routes already did this to keep the routes clean when mounting. Now the user routes do too.
  • [4] TWIZ7QV4 db: Add interface to add a project Right now a project has a name, and an owner which is hardcoded to 1. This is because basically I'm speedrunning to implement push/pull of Pijul and then revisit to add depth to features and tests. Model code is now split into files properly too.
  • [5] W3M3C7CC Initial commit This change includes a very small hello world application server written in Rust using Rocket.rs. Managing dependencies is done with Nix as that works well between Linux and Mac for me.
  • [6] K4JNAJOF database: Connect to postgres on Rocket boot As database I've chosen PostgreSQL, as my personal experience has been good with it. This change allows Rocket to connect to the database on booting the server. It depends on the DATABASE_URL being set, and for now circumvents the Rocket config helpers as it seemed faster to be up and running this way.
  • [7] KFVJ3KMW frontend: Introduce navigation bar Minor changes to the front-end mostly, to allow users to register, sign in, and sign out. The sign out route is changed to a GET endpoint, as links in HTML cannot DELETE.
  • [8] 3E77DEMD routes: Move root route to controllers module The routes were now in modules in the root, which created a messy situation for the future. For now the routes will be moved to the controllers module and later additional changes will be done to further clean this up.
  • [9] Y52KSJEF rocket: User sign up guard forwards over failures When no user can be found, the User implementation of FromRequest was failing, which is a mistake. This meant that no other routes were tried and thus assigning policies to routes failed. This changes fixes that by forwarding instead. To be frank, this is over forwarding, and can still be improved on.
  • [10] FS2NWBVN pijul: Start of push/pull work This change includes one API endpoint, .pijul. It allows for getting a channels remote ID. A lot of plumbing around repositories is added too, from init to opening pristine and actions like it.
  • [11] 5UNA2DEA routes: Register and authenticate users Allow users to sign up, and sign in/sign out. The routes are added, though the design of the pages is very bare bones still, it's hard to go through the full flow to demo. On the server side: Passwords are stored encrypted in the database with salts. This uses the PG encrypt tooling to prevent against bugs and maintainance costs on this project. When a user is signed in, the user ID is set in a private cookie. Rocket has Guards for routes, which has not been implemented yet for this project.
  • [12] S6TFYMRG routes: Move pijul routes to controllers module As with the root routes, now the pijul routes are moved. The mounting of the routes is still done in main.rs though the controller module now collects them. This should DRY this code
  • [13] RJ75MX6Y routes: Move user routes to controllers module The last routes to move, the src directory now only has a main.rs file and directories.

Change contents

  • replacement in src/main.rs at line 1
    [3.212][3.5252:5267](),[3.5267][3.213:253](),[3.212][3.213:253](),[3.253][3.5268:5304](),[3.5304][3.760:761](),[3.253][3.760:761](),[3.254][3.254:288](),[3.288][3.8017:8018](),[3.8018][3.5305:5332](),[3.5332][3.8054:8055](),[3.8054][3.8054:8055](),[3.8055][3.0:17](),[3.17][3.8055:8067](),[3.8055][3.8055:8067](),[3.8078][3.288:318](),[3.288][3.288:318](),[3.318][3.5345:5456](),[3.5456][3.772:792](),[3.318][3.772:792](),[3.792][3.8079:8151](),[3.8151][3.5457:5506](),[3.5544][3.18:61](),[3.61][3.823:882](),[3.2787][3.823:882](),[3.8399][3.823:882](),[3.823][3.823:882](),[3.882][2.2935:3779]()
    use std::env;
    use rocket::fs::{relative, FileServer};
    use rocket_dyn_templates::Template;
    #[macro_use]
    extern crate rocket;
    mod database;
    mod repoman;
    mod controllers;
    mod models;
    #[launch]
    fn rocket() -> _ {
    let repo_storage_root =
    env::var("REPOSITORY_ROOT").expect("No REPOSITORY_ROOT env var exposed");
    rocket::build()
    .attach(database::stage())
    .attach(Template::fairing())
    .manage(repoman::new(repo_storage_root))
    .mount("/", controllers::routes())
    .mount("/", FileServer::from(relative!("static")))
    }
    /// this macro is lifted from the upstream unreleased code.
    #[macro_export]
    macro_rules! context {
    ($($key:ident $(: $value:expr)?),*$(,)?) => {{
    use rocket::serde::ser::{Serialize, Serializer, SerializeMap};
    use ::std::fmt::{Debug, Formatter};
    #[allow(non_camel_case_types)]
    struct ContextMacroCtxObject<$($key: Serialize),*> {
    $($key: $key),*
    }
    #[allow(non_camel_case_types)]
    impl<$($key: Serialize),*> Serialize for ContextMacroCtxObject<$($key),*> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where S: Serializer,
    {
    let mut map = serializer.serialize_map(None)?;
    $(map.serialize_entry(stringify!($key), &self.$key)?;)*
    map.end()
    }
    }
    [3.212]
    [2.3779]
    use futures::executor::block_on;
    use nidobyte;
  • replacement in src/main.rs at line 4
    [2.3780][2.3780:4224]()
    #[allow(non_camel_case_types)]
    impl<$($key: Debug + Serialize),*> Debug for ContextMacroCtxObject<$($key),*> {
    fn fmt(&self, f: &mut Formatter<'_>) -> ::std::fmt::Result {
    f.debug_struct("context!")
    $(.field(stringify!($key), &self.$key))*
    .finish()
    }
    }
    ContextMacroCtxObject {
    $($key $(: $value)?),*
    }
    }};
    [2.3780]
    [3.388]
    fn main() {
    block_on(async_main())
  • edit in src/main.rs at line 7
    [3.390][3.390:468]()
    #[cfg(test)]
    mod test {
    use super::rocket;
    use rocket::http::Status;
  • replacement in src/main.rs at line 8
    [3.469][3.469:816]()
    #[test]
    fn test_hello() {
    use rocket::local::blocking::Client;
    let client = Client::tracked(rocket()).unwrap();
    let response = client.get("/").dispatch();
    assert_eq!(response.status(), Status::Ok);
    let body = response.into_string().unwrap();
    assert!(body.contains("Hello, world!"));
    }
    [3.469]
    [3.816]
    async fn async_main() {
    let rocket = nidobyte::rocket();
    rocket
    .await
    .ignite()
    .await
    .expect("rocket failed to ignite")
    .launch()
    .await
    .expect("failed to launch rocket");
  • replacement in src/controllers/users.rs at line 14
    [3.363][3.363:437]()
    // TODO decide if this routing file is the place for this guard to be at?
    [3.363]
    [3.437]
    // TODO decide if this controller file is the place for this guard to be at?
    // Feels like a constructor for a model, thus needs moving
  • edit in Cargo.toml at line 11
    [3.6272]
    [3.4577]
    futures = "0.3"
  • edit in Cargo.toml at line 14
    [3.4611]
    [3.6273]
    tokio = "1"
  • edit in Cargo.lock at line 1566
    [3.14495]
    [3.4612]
    "futures",
  • edit in Cargo.lock at line 1575
    [3.9227]
    [3.14510]
    "tokio",