-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvalidate.rs
More file actions
223 lines (195 loc) · 7.42 KB
/
validate.rs
File metadata and controls
223 lines (195 loc) · 7.42 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
use predicates::prelude::*;
use superconsole::{
style::{style, Color, Stylize},
Line, Span,
};
use tempfile::{tempdir, TempDir};
use crate::{
command_builder::CommandBuilder,
utils::{
generate_mock_codeowners, generate_mock_git_repo, generate_mock_invalid_junit_xmls,
generate_mock_missing_filepath_suboptimal_junit_xmls, generate_mock_suboptimal_junit_xmls,
generate_mock_valid_junit_xmls, write_junit_xml_to_dir,
},
};
#[test]
fn validate_success() {
let temp_dir = tempdir().unwrap();
generate_mock_valid_junit_xmls(&temp_dir);
generate_mock_codeowners(&temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.success()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("0")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" errors")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("0")).with(Color::Green)).unwrap(),
Span::new_unstyled(String::from(" valid files, ")).unwrap(),
Span::new_styled(style(String::from("1")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" file with warnings, and ")).unwrap(),
Span::new_styled(style(String::from("0")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" files with errors, with 1 file total")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains("Checking for codeowners file..."))
.stderr(predicate::str::contains("Found codeowners path:"));
println!("{assert}");
}
#[test]
fn validate_junit_and_bep() {
let temp_dir = tempdir().unwrap();
let assert = CommandBuilder::validate(temp_dir.path())
.bazel_bep_path("bep.json")
.command()
.arg("--junit-paths")
.arg("./*")
.assert()
.failure()
.stderr(predicate::str::contains("the argument '--bazel-bep-path <BAZEL_BEP_PATH>' cannot be used with '--junit-paths <JUNIT_PATHS>'"));
println!("{assert}");
}
#[test]
fn validate_no_junits() {
let temp_dir = tempdir().unwrap();
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.failure()
.stderr(predicate::str::contains(
"No test output files found to validate",
));
println!("{assert}");
}
#[test]
fn validate_empty_junit_paths() {
let temp_dir = tempdir().unwrap();
let assert = CommandBuilder::validate(temp_dir.path())
.junit_paths("")
.command()
.assert()
.failure()
.stderr(predicate::str::contains(
"error: a value is required for '--junit-paths <JUNIT_PATHS>' but none was supplied",
));
println!("{assert}");
}
#[test]
fn validate_invalid_junits_no_codeowners() {
let temp_dir = tempdir().unwrap();
generate_mock_invalid_junit_xmls(&temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.failure()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("0")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" warnings, and ")).unwrap(),
Span::new_styled(style(String::from("1")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" error")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains("test suite names are missing"))
.stderr(predicate::str::contains("Checking for codeowners file..."))
.stderr(predicate::str::contains("No codeowners file found"));
println!("{assert}");
}
#[test]
fn validate_empty_xml() {
let temp_dir = tempdir().unwrap();
let empty_xml = "";
write_junit_xml_to_dir(empty_xml, &temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.success()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("1")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" warning, and ")).unwrap(),
Span::new_styled(style(String::from("0")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" errors")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains("no reports found"));
println!("{assert}");
}
#[test]
fn validate_invalid_xml() {
let temp_dir = tempdir().unwrap();
let invalid_xml = "<bad<attrs<><><";
write_junit_xml_to_dir(invalid_xml, &temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.failure()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("0")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" warnings, and ")).unwrap(),
Span::new_styled(style(String::from("1")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" error")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains("syntax error: tag not closed"));
println!("{assert}");
}
#[test]
fn validate_suboptimal_junits() {
let temp_dir = TempDir::with_prefix("not-hidden").unwrap();
generate_mock_suboptimal_junit_xmls(&temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.success()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("1")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" warning, and ")).unwrap(),
Span::new_styled(style(String::from("0")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" errors")).unwrap(),
])
.render(),
))
.stderr(predicate::str::contains(
"report has stale (> 1 hour(s)) timestamps",
));
println!("{assert}");
}
#[test]
fn validate_missing_filepath_suboptimal_junits() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_missing_filepath_suboptimal_junit_xmls(&temp_dir);
generate_mock_codeowners(&temp_dir);
let assert = CommandBuilder::validate(temp_dir.path())
.command()
.assert()
.success()
.stderr(predicate::str::contains(
Line::from_iter([
Span::new_styled(style(String::from("2")).with(Color::Yellow)).unwrap(),
Span::new_unstyled(String::from(" warnings, and ")).unwrap(),
Span::new_styled(style(String::from("0")).with(Color::Red)).unwrap(),
Span::new_unstyled(String::from(" errors")).unwrap(),
]).render(),
))
.stderr(predicate::str::contains(
"report has test cases with missing file or filepath",
))
.stderr(predicate::str::contains(
"CODEOWNERS found but test cases are missing filepaths. We will not be able to correlate flaky tests with owners.",
));
println!("{assert}");
}