-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathintegration_tests.rs
59 lines (53 loc) · 2.26 KB
/
integration_tests.rs
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
/*
* Copyright 2022-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//! Integration test that runs the handwritten test cases from
//! `cedar-integration-tests` on the definitional implementation.
use cedar_policy::integration_testing::{
perform_integration_test_from_json_custom, resolve_integration_test_path, CustomCedarImpl,
};
use cedar_drt::*;
use std::path::Path;
use walkdir::WalkDir;
/// Path of the folder containing the integration tests
fn folder() -> &'static Path {
Path::new("tests")
}
fn run_integration_tests(custom_impl: &dyn CustomCedarImpl) {
let integration_tests_folder = resolve_integration_test_path(folder());
// find all `*.json` files in the integration tests folder
let test_jsons = WalkDir::new(&integration_tests_folder)
.into_iter()
.map(|e| e.expect("failed to access file in tests").into_path())
// ignore non-JSON files (and directories, which don't have an extension)
.filter(|p| {
p.extension()
.map(|ext| ext.eq_ignore_ascii_case("json"))
.unwrap_or(false)
});
for test_json in test_jsons {
// These messages are for progress reporting and so that if the
// `#[test]` fails, the user can know which test case failed by looking
// for the last "Running integration test" message before the failure.
println!("Running integration test: {:?}", test_json);
perform_integration_test_from_json_custom(&test_json, Some(custom_impl));
println!("Integration test succeeded: {:?}", test_json);
}
}
#[test]
fn integration_tests_on_def_impl() {
let lean_def_impl = LeanDefinitionalEngine::new();
run_integration_tests(&lean_def_impl);
}