1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
extern crate tempfile;
use std::io::Write;
use std::process::Command;
use std::vec::Vec;
use tempfile::NamedTempFile;
fn client(args: &[&str]) -> 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()
}
fn client_with_config(args: &[&str], cfg: &str) -> String {
let mut file = NamedTempFile::new().unwrap();
let _ = file.write_all(cfg.as_bytes()).unwrap();
let arg: String = "--config=".to_string() + file.path().to_str().unwrap();
let mut args: Vec<&str> = args.to_vec();
args.push(&arg);
client(&args)
}
#[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
--ota-packages-dir PATH
change downloaded directory for packages
--ota-package-manager MANAGER
change package manager
--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(&[""]),
r#"Trying to acquire access token.
Authentication error, didn't receive access token: connection refused
"#)
}
#[test]
fn bad_section() {
assert_eq!(client_with_config(&[""], "[uth]"),
"Failed to parse config: invalid section: auth\n")
}
#[test]
fn bad_toml() {
assert_eq!(client_with_config(&[""], "auth]"),
"Failed to parse config: invalid toml\n")
}
#[test]
fn bad_path_dir() {
assert_eq!(client(&["--config=/"]),
"Failed to load config: Is a directory (os error 21)\n")
}
|