summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTxus <me@txus.io>2016-03-15 18:06:03 +0100
committerTxus <me@txus.io>2016-03-16 14:26:33 +0100
commit574b75f05a386e356699ad85818785c0ac9edc7f (patch)
treee851f513ff794f4dacc1bc88221ec484b51b1df3 /tests
parentcfb71ec6a0c1b22db72de7a2fcc119d5ad3575e8 (diff)
downloadrvi_sota_client-574b75f05a386e356699ad85818785c0ac9edc7f.tar.gz
Test AuthPlus and Ota clients
Also move binary tests to tests/ folder, to avoid the temptation of changing something in main and thinking the tests will cover that (they need a `cargo build` before running).
Diffstat (limited to 'tests')
-rw-r--r--tests/ota_plus_client_tests.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/ota_plus_client_tests.rs b/tests/ota_plus_client_tests.rs
new file mode 100644
index 0000000..a769c9e
--- /dev/null
+++ b/tests/ota_plus_client_tests.rs
@@ -0,0 +1,52 @@
+use std::ffi::OsStr;
+use std::process::Command;
+
+fn client<S: AsRef<OsStr>>(args: &[S]) -> String {
+ let output = Command::new("target/debug/ota_plus_client")
+ .args(args)
+ .output()
+ .unwrap_or_else(|e| { panic!("failed to execute child: {}", e) });
+ return String::from_utf8(output.stdout).unwrap()
+}
+
+#[test]
+fn help() {
+
+ assert_eq!(client(&["-h"]),
+ r#"Usage: target/debug/ota_plus_client [options]
+
+Options:
+ -h, --help print this help menu
+ --config PATH change config path
+ --auth-server URL
+ change the auth server URL
+ --auth-client-id ID
+ change auth client id
+ --auth-secret SECRET
+ change auth secret
+ --ota-server URL
+ change ota server URL
+ --ota-vin VIN change ota vin
+ --test-looping enable read-interpret test loop
+
+"#);
+
+}
+
+#[test]
+fn bad_auth_server_url() {
+ assert_eq!(client(&["--auth-server", "apa"]),
+ "Invalid auth-server URL: relative URL without a base\n");
+}
+
+#[test]
+fn bad_ota_server_url() {
+ assert_eq!(client(&["--ota-server", "apa"]),
+ "Invalid ota-server URL: relative URL without a base\n");
+}
+
+#[test]
+fn no_auth_server_to_connect_to() {
+ assert_eq!(client(&[""]),
+ "Authentication error, Can\'t get AuthPlus token: Cannot send request: connection refused\n");
+}