Chapter 3.9
+ Update tests to incorporate new structure. + Adjust tests to connect to database
This commit is contained in:
parent
6322ed3f5f
commit
3c97b96cf1
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
|||||||
.vscode
|
.vscode
|
||||||
#.env
|
#.env
|
||||||
.gitlab-ci-local
|
.gitlab-ci-local
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
# Added by cargo
|
# Added by cargo
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub database: DatabaseSettings,
|
pub database: DatabaseSettings,
|
||||||
@ -17,9 +16,10 @@ pub struct DatabaseSettings {
|
|||||||
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
||||||
// initialise config reader
|
// initialise config reader
|
||||||
let settings = config::Config::builder()
|
let settings = config::Config::builder()
|
||||||
.add_source(
|
.add_source(config::File::new(
|
||||||
config::File::new("configuration.yaml", config::FileFormat::Yaml)
|
"configuration.yaml",
|
||||||
)
|
config::FileFormat::Yaml,
|
||||||
|
))
|
||||||
.build()?;
|
.build()?;
|
||||||
settings.try_deserialize::<Settings>()
|
settings.try_deserialize::<Settings>()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::net::TcpListener;
|
|
||||||
use mail_app::startup::run;
|
|
||||||
use mail_app::configuration::get_configuration;
|
use mail_app::configuration::get_configuration;
|
||||||
|
use mail_app::startup::run;
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), std::io::Error> {
|
async fn main() -> Result<(), std::io::Error> {
|
||||||
|
@ -2,8 +2,8 @@ use actix_web::{web, HttpResponse};
|
|||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct FormData {
|
pub struct FormData {
|
||||||
email: String,
|
// email: String,
|
||||||
name: String,
|
// name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn subscribe(_form: web::Form<FormData>) -> HttpResponse {
|
pub async fn subscribe(_form: web::Form<FormData>) -> HttpResponse {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use actix_web::{web, App, HttpServer};
|
|
||||||
use actix_web::dev::Server;
|
|
||||||
use std::net::TcpListener;
|
|
||||||
use crate::routes::{health_check, subscribe};
|
use crate::routes::{health_check, subscribe};
|
||||||
|
use actix_web::dev::Server;
|
||||||
|
use actix_web::{web, App, HttpServer};
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
|
pub fn run(listener: TcpListener) -> Result<Server, std::io::Error> {
|
||||||
let server = HttpServer::new(|| {
|
let server = HttpServer::new(|| {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::net::TcpListener;
|
|
||||||
use sqlx::{PgConnection, Connection};
|
|
||||||
use mail_app::startup::run;
|
|
||||||
use mail_app::configuration::get_configuration;
|
use mail_app::configuration::get_configuration;
|
||||||
|
use mail_app::startup::run;
|
||||||
|
use sqlx::{Connection, PgConnection};
|
||||||
|
use std::net::TcpListener;
|
||||||
|
|
||||||
fn spawn_app() -> String {
|
fn spawn_app() -> String {
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to random port.");
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to random port.");
|
||||||
|
Loading…
Reference in New Issue
Block a user