Skip to content

Commit e8f98de

Browse files
authored
adjust mock path to certs which is fix for abrupt mock process finish… (#202)
* adjust mock path to certs which is fix for abrupt mock process finish. Added integration test for mock startup and exposed exception which was silenced * change port of mock in integration test
1 parent a6f3552 commit e8f98de

File tree

9 files changed

+96
-11
lines changed

9 files changed

+96
-11
lines changed

Cargo.lock

+28-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitup/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,15 @@ tokio-stream = { version = "0.1.8", features = ["net"] }
7171
[dev-dependencies]
7272
quickcheck = "0.9"
7373
quickcheck_macros = "0.9"
74+
assert_fs ="1.0"
75+
assert_cmd = "1.0"
7476

7577
[dependencies.reqwest]
7678
version = "0.10.10"
7779
default-features = false
7880
features = ["blocking", "rustls-tls", "json"]
81+
82+
[dev-dependencies.reqwest]
83+
version = "0.10.10"
84+
default-features = false
85+
features = ["blocking", "rustls-tls","native-tls", "json"]

vitup/example/mock/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"port": 80,
2+
"port": 8080,
33
"working_dir": "./mock",
44
"ideascale": false
55
}

vitup/example/mock/https.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"working_dir": "./mock",
44
"ideascale": false,
55
"protocol": {
6-
"key_path": "../resources/tls/server.key",
7-
"cert_path": "../resources/tls/server.crt"
6+
"key_path": "./resources/tls/server.key",
7+
"cert_path": "./resources/tls/server.crt"
88
}
99
}

vitup/src/cli/start/mock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl MockStartCommandArgs {
3131

3232
let control_context = Arc::new(Mutex::new(Context::new(configuration, start_params)?));
3333

34-
tokio::spawn(async move { start_rest_server(control_context.clone()).await })
34+
tokio::spawn(async move { start_rest_server(control_context.clone()).await.unwrap() })
3535
.await
3636
.map(|_| ())
3737
.map_err(Into::into)

vitup/src/config/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,28 +89,28 @@ impl Config {
8989
);
9090

9191
println!(
92-
"refresh timestamp:\t(registration_snapshot_time):\t\t\t{:?}",
92+
"refresh timestamp:\t(registration_snapshot_time):\t\t\t{}",
9393
self.data.snapshot_time
9494
);
9595

9696
println!(
97-
"vote start timestamp:\t(fund_start_time, chain_vote_start_time):\t{:?}",
97+
"vote start timestamp:\t(fund_start_time, chain_vote_start_time):\t{}",
9898
vote_start_timestamp
9999
);
100100
println!(
101-
"tally start timestamp:\t(fund_end_time, chain_vote_end_time):\t\t{:?}",
101+
"tally start timestamp:\t(fund_end_time, chain_vote_end_time):\t\t{}",
102102
tally_start_timestamp
103103
);
104104
println!(
105-
"tally end timestamp:\t(chain_committee_end_time):\t\t\t{:?}",
105+
"tally end timestamp:\t(chain_committee_end_time):\t\t\t{}",
106106
tally_end_timestamp
107107
);
108108
println!(
109-
"next refresh timestamp:\t(next registration_snapshot_time):\t\t{:?}",
109+
"next refresh timestamp:\t(next registration_snapshot_time):\t\t{}",
110110
self.data.next_snapshot_time
111111
);
112112
println!(
113-
"next vote start time:\t(next_fund_start_time):\t\t\t\t{:?}",
113+
"next vote start time:\t(next_fund_start_time):\t\t\t\t{}",
114114
self.data.next_vote_start_time
115115
);
116116
}

vitup/tests/mock/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod startup;

vitup/tests/mock/startup.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use assert_cmd::cargo::CommandCargoExt;
2+
use assert_fs::fixture::PathChild;
3+
use assert_fs::TempDir;
4+
use std::io::Write;
5+
use std::path::Path;
6+
use std::process::Command;
7+
use vitup::mode::mock::Configuration;
8+
9+
pub fn write_config<P: AsRef<Path>>(config: &Configuration, output: P) {
10+
let content = serde_json::to_string(&config).unwrap();
11+
let mut file = std::fs::File::create(&output).unwrap();
12+
file.write_all(content.as_bytes()).unwrap()
13+
}
14+
15+
#[test]
16+
pub fn start_mock() {
17+
let temp_dir = TempDir::new().unwrap();
18+
19+
let configuration = Configuration {
20+
port: 10000,
21+
working_dir: temp_dir.child("mock").path().to_path_buf(),
22+
ideascale: false,
23+
protocol: Default::default(),
24+
token: None,
25+
};
26+
27+
let config_child = temp_dir.child("config.yaml");
28+
let config_file_path = config_child.path();
29+
write_config(&configuration, &config_file_path);
30+
31+
let mut cmd = Command::cargo_bin("vitup").unwrap();
32+
let mut mock_process = cmd
33+
.arg("start")
34+
.arg("mock")
35+
.arg("--config")
36+
.arg(&config_file_path)
37+
.spawn()
38+
.unwrap();
39+
40+
let request = reqwest::blocking::Client::new()
41+
.get(&format!(
42+
"http://localhost:{}/api/health",
43+
configuration.port
44+
))
45+
.send();
46+
47+
mock_process.kill().unwrap();
48+
assert_eq!(request.unwrap().status(), 200);
49+
}

vitup/tests/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
mod data;
2+
mod mock;

0 commit comments

Comments
 (0)