diff options
| author | Teddy Wing | 2018-11-09 20:46:08 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-11-09 20:46:08 +0100 | 
| commit | d7baf68d21a34e51b3ff193fc2d7513c7c270e6c (patch) | |
| tree | 5d53fc552571f6a0e5fe9827ee4c23f8723b188f /license-generator/src | |
| parent | 1c3e4bc7817b6b802e02cbf6c97e95752b2d9f45 (diff) | |
| download | dome-key-web-d7baf68d21a34e51b3ff193fc2d7513c7c270e6c.tar.bz2 | |
main(): Create a test purchaser
Manually check that our purchaser creation and database persistence
works.
Make `purchaser` entities public in order to call them.
Diffstat (limited to 'license-generator/src')
| -rw-r--r-- | license-generator/src/lib.rs | 2 | ||||
| -rw-r--r-- | license-generator/src/main.rs | 9 | ||||
| -rw-r--r-- | license-generator/src/purchaser.rs | 6 | 
3 files changed, 12 insertions, 5 deletions
| diff --git a/license-generator/src/lib.rs b/license-generator/src/lib.rs index 4dd726d..8061142 100644 --- a/license-generator/src/lib.rs +++ b/license-generator/src/lib.rs @@ -8,4 +8,4 @@ extern crate sha1;  pub mod database;  pub mod errors; -mod purchaser; +pub mod purchaser; diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs index 32fdc3b..5c1a0aa 100644 --- a/license-generator/src/main.rs +++ b/license-generator/src/main.rs @@ -15,6 +15,7 @@ use simplelog::{Config, LevelFilter, WriteLogger};  use license_generator::database;  use license_generator::errors::*; +use license_generator::purchaser::Purchaser;  fn main() -> Result<()> {      let log_file_path = env::var("LOG_FILE")?; @@ -26,7 +27,7 @@ fn main() -> Result<()> {      WriteLogger::init(LevelFilter::Info, Config::default(), log_file)?; -    let cx = match database::get_database_connection() +    let mut cx = match database::get_database_connection()          .chain_err(|| "failed to create a database connection")      {          Ok(cx) => cx, @@ -36,6 +37,12 @@ fn main() -> Result<()> {          },      }; +    let test_purchaser = Purchaser::new("Shiki", "shiki@example.com"); +    match test_purchaser.insert(&mut cx) { +        Ok(_) => (), +        Err(e) => error!("{}", e), +    } +      fastcgi::run(|mut req| {          write!(&mut req.stdout(), "Content-Type: text/plain\n\nHello, world!")              .unwrap_or(()); diff --git a/license-generator/src/purchaser.rs b/license-generator/src/purchaser.rs index 445a1dc..cf777d3 100644 --- a/license-generator/src/purchaser.rs +++ b/license-generator/src/purchaser.rs @@ -4,14 +4,14 @@ use sha1;  use errors::*; -struct Purchaser<'a> { +pub struct Purchaser<'a> {      name: &'a str,      email: &'a str,      secret: Option<String>,  }  impl<'a> Purchaser<'a> { -    fn new(name: &'a str, email: &'a str) -> Self { +    pub fn new(name: &'a str, email: &'a str) -> Self {          let mut purchaser = Purchaser {              name: name,              email: email, @@ -33,7 +33,7 @@ impl<'a> Purchaser<'a> {          self.secret = Some(digest);      } -    fn insert(&self, cx: &mut mysql::PooledConn) -> Result<()> { +    pub fn insert(&self, cx: &mut mysql::PooledConn) -> Result<()> {          let mut tx = cx.start_transaction(              false,  // consistent_snapshot              None,   // isolation_level | 
