-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo_format_validation_test.rs
More file actions
95 lines (85 loc) · 3.25 KB
/
todo_format_validation_test.rs
File metadata and controls
95 lines (85 loc) · 3.25 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
//! Tests for package_todo.yml format validation.
//!
//! These tests verify that the `pks validate` command correctly identifies
//! when package_todo.yml files are not in the expected serialization format
//! and provides appropriate error messages and suggestions.
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::{error::Error, process::Command};
mod common;
/// Tests that validation fails for incorrectly formatted package_todo.yml files.
///
/// This test uses a fixture with a package_todo.yml file that has violations in
/// the wrong order (::Baz should come after ::Bar when sorted alphabetically).
/// The validation should fail and suggest running the appropriate update command.
#[test]
fn test_validate_incorrectly_formatted_package_todo(
) -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
.arg("--project-root")
.arg("tests/fixtures/incorrectly_formatted_package_todo")
.arg("validate")
.assert()
.failure()
.stdout(predicate::str::contains("1 validation error(s) detected:"))
.stdout(predicate::str::contains("is not in the expected format"))
.stdout(predicate::str::contains("bin/packwerk update-todo"));
common::teardown();
Ok(())
}
/// Tests that validation passes for correctly formatted package_todo.yml files.
///
/// This test uses an existing fixture that has a properly formatted package_todo.yml
/// file (with correct ordering, headers, and format). The validation should succeed.
#[test]
fn test_validate_correctly_formatted_package_todo() -> Result<(), Box<dyn Error>>
{
Command::cargo_bin("pks")
.unwrap()
.arg("--project-root")
.arg("tests/fixtures/contains_package_todo")
.arg("validate")
.assert()
.success()
.stdout(predicate::str::contains("Packwerk validate succeeded!"));
common::teardown();
Ok(())
}
/// Tests that validation passes when violations exist but no package_todo.yml files.
///
/// This test uses a fixture with actual privacy violations but no package_todo.yml files
/// and verifies that the todo format validator still succeeds (it only validates existing
/// todo files, not whether violations should have todo files).
#[test]
fn test_validate_passes_when_violations_exist_but_no_todo_file(
) -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
.arg("--project-root")
.arg("tests/fixtures/privacy_violation_overrides")
.arg("validate")
.assert()
.success()
.stdout(predicate::str::contains("Packwerk validate succeeded!"));
common::teardown();
Ok(())
}
/// Tests that validation succeeds when there are no violations and no package_todo.yml files.
///
/// This test uses a clean fixture with no violations and no package_todo.yml files
/// to verify the validator succeeds in the simplest case.
#[test]
fn test_validate_succeeds_when_no_violations_and_no_todo_files(
) -> Result<(), Box<dyn Error>> {
Command::cargo_bin("pks")
.unwrap()
.arg("--project-root")
.arg("tests/fixtures/simple_app")
.arg("validate")
.assert()
.success()
.stdout(predicate::str::contains("Packwerk validate succeeded!"));
common::teardown();
Ok(())
}