MCPcopy Index your code
hub / github.com/Rust-Web-Development/code / main

Function main

ch_11/integration-tests/src/main.rs:34–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32
33#[tokio::main]
34async fn main() -> Result<(), handle_errors::Error> {
35 dotenvy::dotenv().ok();
36 let config = config::Config::new().expect("Config can't be set");
37
38 let s = Command::new("sqlx")
39 .arg("database")
40 .arg("drop")
41 .arg("--database-url")
42 .arg(format!("postgres://{}:{}/{}", config.db_host, config.db_port, config.db_name))
43 .arg("-y")
44 .output()
45 .expect("sqlx command failed to start");
46
47 io::stdout().write_all(&s.stderr).unwrap();
48
49 let s = Command::new("sqlx")
50 .arg("database")
51 .arg("create")
52 .arg("--database-url")
53 .arg(format!("postgres://{}:{}/{}", config.db_host, config.db_port, config.db_name))
54 .output()
55 .expect("sqlx command failed to start");
56
57 // Exdcute DB commands to drop and create a new test database
58 io::stdout().write_all(&s.stderr).unwrap();
59
60 // set up a new store instance with a db connection pool
61 let store = setup_store(&config).await?;
62
63 // start the server and listen for a sender signal to shut it down
64 let handler = oneshot(store).await;
65
66 // create a test user to use throughout the tests
67 let u = User {
68 email: "test@email.com".to_string(),
69 password: "password".to_string(),
70 };
71
72 let token;
73
74 print!("Running register_new_user...");
75 let result = std::panic::AssertUnwindSafe(register_new_user(&u)).catch_unwind().await;
76 match result {
77 Ok(_) => println!("✓"),
78 Err(_) => {
79 let _ = handler.sender.send(1);
80 std::process::exit(1);
81 }
82 }
83
84 print!("Running login...");
85 match std::panic::AssertUnwindSafe(login(u)).catch_unwind().await {
86 Ok(t) => {
87 token = t;
88 println!("✓");
89 },
90 Err(_) => {
91 let _ = handler.sender.send(1);

Callers

nothing calls this directly

Calls 5

setup_storeFunction · 0.85
oneshotFunction · 0.85
register_new_userFunction · 0.85
post_questionFunction · 0.85
loginFunction · 0.70

Tested by

no test coverage detected