Skip to content

Commit 27d812e

Browse files
authored
x509-cert: fix test: stuck zlint stdout reader (#1776)
* x509-cert: fix test: stuck zlint stdout reader
1 parent 53d2e3b commit 27d812e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

x509-cert/test-support/src/zlint.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,19 @@ Rounds = 100
140140

141141
pub fn check_certificate(pem: &[u8], ignored: &[&str]) {
142142
let tmp_dir = tempdir().expect("create tempdir");
143-
let config_path = tmp_dir.path().join("config.toml");
144-
let cert_path = tmp_dir.path().join("cert.pem");
143+
let config_path = tmp_dir.path().join("zlint_config.toml");
144+
let cert_path = tmp_dir.path().join("zlint_cert.pem");
145145

146-
let mut config_file = File::create(&config_path).expect("create config file");
147-
config_file
148-
.write_all(ZLINT_CONFIG.as_bytes())
149-
.expect("Create config file");
150-
151-
let mut cert_file = File::create(&cert_path).expect("create pem file");
152-
cert_file.write_all(pem).expect("Create pem file");
146+
{
147+
let mut config_file = File::create(&config_path).expect("create config file");
148+
config_file
149+
.write_all(ZLINT_CONFIG.as_bytes())
150+
.expect("Create config file");
151+
}
152+
{
153+
let mut cert_file = File::create(&cert_path).expect("create pem file");
154+
cert_file.write_all(pem).expect("Create pem file");
155+
}
153156

154157
let mut child = Command::new("zlint")
155158
.arg("-pretty")
@@ -167,13 +170,16 @@ pub fn check_certificate(pem: &[u8], ignored: &[&str]) {
167170
});
168171

169172
let mut stdout = child.stdout.take().unwrap();
173+
174+
let output_buf = {
175+
let mut buf = Vec::new();
176+
stdout.read_to_end(&mut buf).expect("read zlint output");
177+
buf
178+
};
179+
170180
let exit_status = child.wait().expect("get zlint status");
171181

172182
assert!(exit_status.success(), "zlint failed");
173-
let mut output_buf = Vec::new();
174-
stdout
175-
.read_to_end(&mut output_buf)
176-
.expect("read zlint output");
177183

178184
let output: LintResult = serde_json::from_slice(&output_buf).expect("parse zlint output");
179185

0 commit comments

Comments
 (0)