Add integration testing on travis
This commit is contained in:
@@ -6,6 +6,8 @@ rust:
|
||||
- beta
|
||||
- nightly
|
||||
before_script:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -y postfix
|
||||
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
|
||||
script:
|
||||
- |
|
||||
|
||||
79
tests/lib.rs
79
tests/lib.rs
@@ -1,14 +1,71 @@
|
||||
// Copyright 2014 Alexis Mousset. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
extern crate lettre;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
|
||||
use lettre::transport::smtp::SmtpTransportBuilder;
|
||||
use lettre::transport::EmailTransport;
|
||||
use lettre::mailer::Mailer;
|
||||
use lettre::email::EmailBuilder;
|
||||
|
||||
#[test]
|
||||
|
||||
fn foo() {
|
||||
assert!(true);
|
||||
fn simple_sender() {
|
||||
let sender = SmtpTransportBuilder::localhost().unwrap().build();
|
||||
let mut mailer = Mailer::new(sender);
|
||||
let email = EmailBuilder::new()
|
||||
.to("root@localhost")
|
||||
.from("user@localhost")
|
||||
.body("Hello World!")
|
||||
.subject("Hello")
|
||||
.build()
|
||||
.unwrap();
|
||||
let result = mailer.send(email);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multithreaded_sender() {
|
||||
let sender = SmtpTransportBuilder::localhost()
|
||||
.unwrap()
|
||||
.hello_name("localhost")
|
||||
.connection_reuse(true)
|
||||
.build();
|
||||
let mailer = Arc::new(Mutex::new(Mailer::new(sender)));
|
||||
|
||||
let mut threads = Vec::new();
|
||||
for _ in 1..5 {
|
||||
|
||||
let th_mailer = mailer.clone();
|
||||
threads.push(thread::spawn(move || {
|
||||
|
||||
let email = EmailBuilder::new()
|
||||
.to("root@localhost")
|
||||
.from("user@localhost")
|
||||
.body("Hello World!")
|
||||
.subject("Hello")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let result = th_mailer.lock().unwrap().send(email);
|
||||
assert!(result.is_ok());
|
||||
}));
|
||||
}
|
||||
|
||||
for thread in threads {
|
||||
let _ = thread.join();
|
||||
}
|
||||
|
||||
let email = EmailBuilder::new()
|
||||
.to("root@localhost")
|
||||
.from("user@localhost")
|
||||
.body("Hello World!")
|
||||
.subject("Hello Bis")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let mut mailer = mailer.lock().unwrap();
|
||||
let final_result = mailer.send(email);
|
||||
mailer.close();
|
||||
|
||||
assert!(final_result.is_ok());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user