Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

test: Add some basic e2e tests (#61)

Amaury Martiny8500b8cbe82e
diff --git a/Cargo.lock b/Cargo.lock
index 7a72c7f2..90e047f8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -153,6 +153,15 @@ dependencies = [
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "check_if_email_exists_test_suite"
+version = "0.3.2"
+dependencies = [
+ "check_if_email_exists_core 0.3.2",
+ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
[[package]]
name = "chrono"
version = "0.4.9"
diff --git a/Cargo.toml b/Cargo.toml
index 5ea335e1..1c4d9e56 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,5 +16,6 @@ serde_json = "1.0"
[workspace]
members = [
"core",
- "serverless"
+ "serverless",
+ "test_suite"
]
diff --git a/appveyor.yml b/appveyor.yml
index a7088183..14430ec8 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -47,8 +47,8 @@ test_script:
- if [%APPVEYOR_REPO_TAG%]==[false] (
cargo build --target %TARGET% &&
cargo build --target %TARGET% --release &&
- cargo test --target %TARGET% &&
- cargo test --target %TARGET% --release
+ cargo test --all --target %TARGET% &&
+ cargo test --all --target %TARGET% --release
)
before_deploy:
diff --git a/ci/script.sh b/ci/script.sh
index 691ddc8f..9f3a011e 100755
--- a/ci/script.sh
+++ b/ci/script.sh
@@ -11,11 +11,11 @@ main() {
return
fi
- cross test --target $TARGET
- cross test --target $TARGET --release
+ cross test --all --target $TARGET
+ cross test --all --target $TARGET --release
# Run the binary with a $TEST_EMAIL, to test that the tool actually works.
- # aka some quick e2e test
+ # aka some quick e2e test on the binary itself
# TODO This only works on osx now, see #11
if [ $TRAVIS_OS_NAME = osx ]; then
cross run --target $TARGET $TEST_EMAIL | grep "\"deliverable\": true"
diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.toml
new file mode 100644
index 00000000..4f8f4091
--- /dev/null
+++ b/test_suite/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "check_if_email_exists_test_suite"
+version = "0.3.2"
+authors = ["Amaury Martiny <[email protected]>"]
+description = "Check if an email address exists without sending any email"
+edition = "2018"
+publish = false
+
+[dependencies]
+check_if_email_exists_core = { path = "../core" }
+serde = "1.0"
+serde_json = "1.0"
diff --git a/test_suite/src/lib.rs b/test_suite/src/lib.rs
new file mode 100644
index 00000000..79f25876
--- /dev/null
+++ b/test_suite/src/lib.rs
@@ -0,0 +1,47 @@
+// check_if_email_exists
+// Copyright (C) 2018-2019 Amaury Martiny
+
+// check_if_email_exists is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// check_if_email_exists is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with check_if_email_exists. If not, see <http://www.gnu.org/licenses/>.
+
+/// E2E tests
+
+#[cfg(test)]
+mod tests {
+ use check_if_email_exists_core::email_exists;
+
+ #[test]
+ fn should_output_error_for_invalid_email() {
+ assert_eq!(
+ serde_json::to_string(&email_exists("foo", "[email protected]")).unwrap(),
+ "{\"mx\":{\"error\":{\"type\":\"Skipped\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"error\":{\"type\":\"SyntaxError\",\"message\":\"invalid email address\"}}}"
+ );
+ }
+
+ #[test]
+ fn should_output_error_for_invalid_mx() {
+ assert_eq!(
+ serde_json::to_string(&email_exists("[email protected]", "[email protected]")).unwrap(),
+ "{\"mx\":{\"error\":{\"type\":\"ResolveError\",\"message\":\"no record found for name: bar.baz type: MX class: IN\"}},\"smtp\":{\"error\":{\"type\":\"Skipped\"}},\"syntax\":{\"address\":\"[email protected]\",\"domain\":\"bar.baz\",\"username\":\"foo\",\"valid_format\":true}}"
+ );
+ }
+
+ #[test]
+ #[ignore]
+ fn should_output_error_when_blocked_by_isp() {
+ assert_eq!(
+ serde_json::to_string(&email_exists("[email protected]", "[email protected]")).unwrap(),
+ "{\"mx\":{\"records\":[\"in1-smtp.messagingengine.com.\",\"in2-smtp.messagingengine.com.\"]},\"smtp\":{\"error\":{\"type\":\"BlockedByIsp\"}},\"syntax\":{\"address\":\"[email protected]\",\"domain\":\"fastmail.com\",\"username\":\"someone\",\"valid_format\":true}}"
+ );
+ }
+}