8000 trunk-merge/pr-683/0ec49001-f9eb-417c-b4c6-edf47ec09903 by trunk-io[bot] · Pull Request #695 · trunk-io/analytics-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

trunk-merge/pr-683/0ec49001-f9eb-417c-b4c6-edf47ec09903 #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHu 8000 b”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ wasm = []
[dependencies]
anyhow = "1.0.96"
proto = { version = "0.0.0", path = "../proto" }
superconsole = "0.2.0"
103 changes: 76 additions & 27 deletions cli-tests/src/validate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use predicates::prelude::*;
use superconsole::{
style::{style, Color, Stylize},
Line, Span,
};
use tempfile::tempdir;

use crate::{
Expand All @@ -20,10 +24,26 @@ fn validate_success() {
.command()
.assert()
.success()
.stdout(predicate::str::contains("0 validation errors"))
.stdout(predicate::str::contains("All 1 files are valid"))
.stdout(predicate::str::contains("Checking for codeowners file..."))
.stdout(predicate::str::contains("Found codeowners:"));
.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}");
}
Expand Down Expand Up @@ -84,14 +104,18 @@ fn validate_invalid_junits_no_codeowners() {
.command()
.assert()
.failure()
.stdout(predicate::str::contains("1 validation error"))
.stdout(predicate::str::contains(
"INVALID - test suite names are missing",
.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(),
))
.stdout(predicate::str::contains("Checking for codeowners file..."))
.stdout(predicate::str::contains(
"OPTIONAL - No codeowners file found",
));
.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}");
}
Expand All @@ -106,8 +130,16 @@ fn validate_empty_xml() {
.command()
.assert()
.success()
.stdout(predicate::str::contains("1 validation warning"))
.stdout(predicate::str::contains("OPTIONAL - no reports found"));
.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}");
}
Expand All @@ -122,10 +154,16 @@ fn validate_invalid_xml() {
.command()
.assert()
.failure()
.stdout(predicate::str::contains("1 validation error"))
.stdout(predicate::str::contains(
"INVALID - syntax error: tag not closed",
));
.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}");
}
Expand All @@ -139,11 +177,17 @@ fn validate_suboptimal_junits() {
.command()
.assert()
.success()
.stdout(predicate::str::contains(
"0 validation errors, 1 validation warning",
.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(),
))
.stdout(predicate::str::contains(
"OPTIONAL - report has stale (> 1 hour(s)) timestamps",
.stderr(predicate::str::contains(
"report has stale (> 1 hour(s)) timestamps",
));

println!("{assert}");
Expand All @@ -159,14 +203,19 @@ fn validate_missing_filepath_suboptimal_junits() {
.command()
.assert()
.success()
.stdout(predicate::str::contains(
"0 validation errors, 2 validation warning",
.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(),
))
.stdout(predicate::str::contains(
"OPTIONAL - report has test cases with missing file or filepath",
.stderr(predicate::str::contains(
"report has test cases with missing file or filepath",
))
.stdout(predicate::str::contains(
"OPTIONAL - CODEOWNERS found but test cases are missing filepaths. We will not be able to correlate flaky tests with owners.",
.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}");
Expand Down
15 changes: 10 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use trunk_analytics_cli::{
error_report::ErrorReport,
test_command::{run_test, TestArgs},
upload_command::{run_upload, UploadArgs, UploadRunResult},
validate_command::{run_validate, ValidateArgs},
validate_command::{run_validate, ValidateArgs, ValidateRunResult},
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -85,7 +85,7 @@ enum Commands {
Test(TestArgs),
/// Upload data to Trunk Flaky Tests
Upload(UploadArgs),
/// Validate that your test runner output is suitable for Trunk Flaky Tests
/// Validate that your test runner output is suitable for Trunk Flaky Tests (does not call to servers)
Validate(ValidateArgs),
}

Expand Down Expand Up @@ -154,8 +154,13 @@ fn main() -> anyhow::Result<()> {
render_handle,
)
}
Ok(RunResult::Validate(exit_code)) => {
close_out_and_exit(exit_code, guard, render_sender, render_handle)
Ok(RunResult::Validate(run_result)) => {
let result_ptr = Arc::new(run_result);
send_message(
DisplayMessage::Final(result_ptr.clone(), String::from("validate display")),
&render_sender,
);
close_out_and_exit(result_ptr.exit_code(), guard, render_sender, render_handle)
}
Err(error) => {
let error_report = ErrorReport::new(error, org_url_slug, None);
Expand All @@ -176,7 +181,7 @@ fn main() -> anyhow::Result<()> {
enum RunResult {
Upload(UploadRunResult),
Test(UploadRunResult),
Validate(i32),
Validate(ValidateRunResult),
}

async fn run(cli: Cli, render_sender: Sender<DisplayMessage>) -> anyhow::Result<RunResult> {
Expand Down
Loading
0