Skip to content

Commit c8645ff

Browse files
committed
Factorize api spec verification tests
1 parent bed6179 commit c8645ff

File tree

6 files changed

+213
-217
lines changed

6 files changed

+213
-217
lines changed

mithril-aggregator/src/http_server/routes/certificate_routes.rs

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,14 @@ mod tests {
123123
.reply(&setup_router(Arc::new(dependency_manager)))
124124
.await;
125125

126-
for spec_file in APISpec::get_all_spec_files() {
127-
APISpec::from_file(&spec_file)
128-
.method(method)
129-
.path(path)
130-
.validate_request(&Null)
131-
.unwrap()
132-
.validate_response(&response)
133-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
134-
}
126+
APISpec::verify_conformity(
127+
APISpec::get_all_spec_files(),
128+
method,
129+
path,
130+
"application/json",
131+
&Null,
132+
&response,
133+
);
135134
}
136135

137136
#[tokio::test]
@@ -147,15 +146,14 @@ mod tests {
147146
.reply(&setup_router(Arc::new(dependency_manager)))
148147
.await;
149148

150-
for spec_file in APISpec::get_all_spec_files() {
151-
APISpec::from_file(&spec_file)
152-
.method(method)
153-
.path(path)
154-
.validate_request(&Null)
155-
.unwrap()
156-
.validate_response(&response)
157-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
158-
}
149+
APISpec::verify_conformity(
150+
APISpec::get_all_spec_files(),
151+
method,
152+
path,
153+
"application/json",
154+
&Null,
155+
&response,
156+
);
159157
}
160158

161159
#[tokio::test]
@@ -170,15 +168,14 @@ mod tests {
170168
.reply(&setup_router(Arc::new(dependency_manager)))
171169
.await;
172170

173-
for spec_file in APISpec::get_all_spec_files() {
174-
APISpec::from_file(&spec_file)
175-
.method(method)
176-
.path(path)
177-
.validate_request(&Null)
178-
.unwrap()
179-
.validate_response(&response)
180-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
181-
}
171+
APISpec::verify_conformity(
172+
APISpec::get_all_spec_files(),
173+
method,
174+
path,
175+
"application/json",
176+
&Null,
177+
&response,
178+
);
182179
}
183180

184181
#[tokio::test]
@@ -199,15 +196,14 @@ mod tests {
199196
.reply(&setup_router(Arc::new(dependency_manager)))
200197
.await;
201198

202-
for spec_file in APISpec::get_all_spec_files() {
203-
APISpec::from_file(&spec_file)
204-
.method(method)
205-
.path(path)
206-
.validate_request(&Null)
207-
.unwrap()
208-
.validate_response(&response)
209-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
210-
}
199+
APISpec::verify_conformity(
200+
APISpec::get_all_spec_files(),
201+
method,
202+
path,
203+
"application/json",
204+
&Null,
205+
&response,
206+
);
211207
}
212208

213209
#[tokio::test]
@@ -223,15 +219,14 @@ mod tests {
223219
.reply(&setup_router(Arc::new(dependency_manager)))
224220
.await;
225221

226-
for spec_file in APISpec::get_all_spec_files() {
227-
APISpec::from_file(&spec_file)
228-
.method(method)
229-
.path(path)
230-
.validate_request(&Null)
231-
.unwrap()
232-
.validate_response(&response)
233-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
234-
}
222+
APISpec::verify_conformity(
223+
APISpec::get_all_spec_files(),
224+
method,
225+
path,
226+
"application/json",
227+
&Null,
228+
&response,
229+
);
235230
}
236231

237232
#[tokio::test]
@@ -252,14 +247,13 @@ mod tests {
252247
.reply(&setup_router(Arc::new(dependency_manager)))
253248
.await;
254249

255-
for spec_file in APISpec::get_all_spec_files() {
256-
APISpec::from_file(&spec_file)
257-
.method(method)
258-
.path(path)
259-
.validate_request(&Null)
260-
.unwrap()
261-
.validate_response(&response)
262-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
263-
}
250+
APISpec::verify_conformity(
251+
APISpec::get_all_spec_files(),
252+
method,
253+
path,
254+
"application/json",
255+
&Null,
256+
&response,
257+
);
264258
}
265259
}

mithril-aggregator/src/http_server/routes/epoch_routes.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@ mod tests {
118118
.reply(&setup_router(Arc::new(dependency_manager)))
119119
.await;
120120

121-
for spec_file in APISpec::get_all_spec_files() {
122-
APISpec::from_file(&spec_file)
123-
.method(method)
124-
.path(path)
125-
.validate_request(&Null)
126-
.unwrap()
127-
.validate_response(&response)
128-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
129-
}
121+
APISpec::verify_conformity(
122+
APISpec::get_all_spec_files(),
123+
method,
124+
path,
125+
"application/json",
126+
&Null,
127+
&response,
128+
);
130129
}
131130

132131
#[tokio::test]
@@ -141,14 +140,13 @@ mod tests {
141140
.reply(&setup_router(Arc::new(dependency_manager)))
142141
.await;
143142

144-
for spec_file in APISpec::get_all_spec_files() {
145-
APISpec::from_file(&spec_file)
146-
.method(method)
147-
.path(path)
148-
.validate_request(&Null)
149-
.unwrap()
150-
.validate_response(&response)
151-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
152-
}
143+
APISpec::verify_conformity(
144+
APISpec::get_all_spec_files(),
145+
method,
146+
path,
147+
"application/json",
148+
&Null,
149+
&response,
150+
);
153151
}
154152
}

mithril-aggregator/src/http_server/routes/signatures_routes.rs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ mod tests {
105105
.reply(&setup_router(Arc::new(dependency_manager)))
106106
.await;
107107

108-
for spec_file in APISpec::get_all_spec_files() {
109-
APISpec::from_file(&spec_file)
110-
.method(method)
111-
.path(path)
112-
.validate_request(&message)
113-
.unwrap()
114-
.validate_response(&response)
115-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
116-
}
108+
APISpec::verify_conformity(
109+
APISpec::get_all_spec_files(),
110+
method,
111+
path,
112+
"application/json",
113+
&message,
114+
&response,
115+
);
117116
}
118117

119118
#[tokio::test]
@@ -138,15 +137,14 @@ mod tests {
138137
.reply(&setup_router(Arc::new(dependency_manager)))
139138
.await;
140139

141-
for spec_file in APISpec::get_all_spec_files() {
142-
APISpec::from_file(&spec_file)
143-
.method(method)
144-
.path(path)
145-
.validate_request(&message)
146-
.unwrap()
147-
.validate_response(&response)
148-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
149-
}
140+
APISpec::verify_conformity(
141+
APISpec::get_all_spec_files(),
142+
method,
143+
path,
144+
"application/json",
145+
&message,
146+
&response,
147+
);
150148
}
151149

152150
#[tokio::test]
@@ -173,15 +171,14 @@ mod tests {
173171
.reply(&setup_router(Arc::new(dependency_manager)))
174172
.await;
175173

176-
for spec_file in APISpec::get_all_spec_files() {
177-
APISpec::from_file(&spec_file)
178-
.method(method)
179-
.path(path)
180-
.validate_request(&message)
181-
.unwrap()
182-
.validate_response(&response)
183-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
184-
}
174+
APISpec::verify_conformity(
175+
APISpec::get_all_spec_files(),
176+
method,
177+
path,
178+
"application/json",
179+
&message,
180+
&response,
181+
);
185182
}
186183

187184
#[tokio::test]
@@ -208,14 +205,13 @@ mod tests {
208205
.reply(&setup_router(Arc::new(dependency_manager)))
209206
.await;
210207

211-
for spec_file in APISpec::get_all_spec_files() {
212-
APISpec::from_file(&spec_file)
213-
.method(method)
214-
.path(path)
215-
.validate_request(&message)
216-
.unwrap()
217-
.validate_response(&response)
218-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
219-
}
208+
APISpec::verify_conformity(
209+
APISpec::get_all_spec_files(),
210+
method,
211+
path,
212+
"application/json",
213+
&message,
214+
&response,
215+
);
220216
}
221217
}

mithril-aggregator/src/http_server/routes/signer_routes.rs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ mod tests {
163163
.reply(&setup_router(Arc::new(dependency_manager)))
164164
.await;
165165

166-
for spec_file in APISpec::get_all_spec_files() {
167-
APISpec::from_file(&spec_file)
168-
.method(method)
169-
.path(path)
170-
.validate_request(&signer)
171-
.unwrap()
172-
.validate_response(&response)
173-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
174-
}
166+
APISpec::verify_conformity(
167+
APISpec::get_all_spec_files(),
168+
method,
169+
path,
170+
"application/json",
171+
&signer,
172+
&response,
173+
);
175174
}
176175

177176
#[tokio::test]
@@ -196,15 +195,14 @@ mod tests {
196195
.reply(&setup_router(Arc::new(dependency_manager)))
197196
.await;
198197

199-
for spec_file in APISpec::get_all_spec_files() {
200-
APISpec::from_file(&spec_file)
201-
.method(method)
202-
.path(path)
203-
.validate_request(&signer)
204-
.unwrap()
205-
.validate_response(&response)
206-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
207-
}
198+
APISpec::verify_conformity(
199+
APISpec::get_all_spec_files(),
200+
method,
201+
path,
202+
"application/json",
203+
&signer,
204+
&response,
205+
);
208206
}
209207

210208
#[tokio::test]
@@ -232,15 +230,14 @@ mod tests {
232230
.reply(&setup_router(Arc::new(dependency_manager)))
233231
.await;
234232

235-
for spec_file in APISpec::get_all_spec_files() {
236-
APISpec::from_file(&spec_file)
237-
.method(method)
238-
.path(path)
239-
.validate_request(&signer)
240-
.unwrap()
241-
.validate_response(&response)
242-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
243-
}
233+
APISpec::verify_conformity(
234+
APISpec::get_all_spec_files(),
235+
method,
236+
path,
237+
"application/json",
238+
&signer,
239+
&response,
240+
);
244241
}
245242

246243
#[tokio::test]
@@ -267,14 +264,13 @@ mod tests {
267264
.reply(&setup_router(Arc::new(dependency_manager)))
268265
.await;
269266

270-
for spec_file in APISpec::get_all_spec_files() {
271-
APISpec::from_file(&spec_file)
272-
.method(method)
273-
.path(path)
274-
.validate_request(&signer)
275-
.unwrap()
276-
.validate_response(&response)
277-
.unwrap_or_else(|_| panic!("OpenAPI error in {}", spec_file));
278-
}
267+
APISpec::verify_conformity(
268+
APISpec::get_all_spec_files(),
269+
method,
270+
path,
271+
"application/json",
272+
&signer,
273+
&response,
274+
);
279275
}
280276
}

0 commit comments

Comments
 (0)