Skip to content

Commit

Permalink
[TRUNK-12978] v1 validate command (#129)
Browse files Browse the repository at this point in the history
* validate v1

* common cli-tests utils

* undo original_path -> original_path_abs

* print file path for parsing error

* pr feedback

* rm comment

* pr feedback; shannon feedback

* more pr feedback
  • Loading branch information
max-trunk authored Oct 17, 2024
1 parent 82e276d commit 2fea36d
Show file tree
Hide file tree
Showing 13 changed files with 656 additions and 75 deletions.
137 changes: 120 additions & 17 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions cli-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#[cfg(test)]
mod upload;
#[cfg(test)]
mod utils;
#[cfg(test)]
mod validate;

fn main() {}
45 changes: 5 additions & 40 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use std::{
env, fs,
io::BufReader,
path::{Path, PathBuf},
};
use std::{fs, io::BufReader};

use crate::utils::{
generate_mock_codeowners, generate_mock_git_repo, generate_mock_valid_junit_xmls, CARGO_RUN,
};
use api::{
BundleUploadStatus, CreateRepoRequest, GetQuarantineBulkTestStatusRequest,
UpdateBundleUploadRequest,
};
use assert_cmd::Command;
use assert_matches::assert_matches;
use context::repo::RepoUrlParts as Repo;
use escargot::{CargoBuild, CargoRun};
use junit_mock::JunitMock;
use lazy_static::lazy_static;
use tempfile::tempdir;
use test_utils::{
mock_git_repo::setup_repo_with_commit,
Expand All @@ -24,43 +20,12 @@ use trunk_analytics_cli::{
types::{BundleMeta, FileSetType},
};

lazy_static! {
static ref CARGO_MANIFEST_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
static ref CARGO_RUN: CargoRun = CargoBuild::new()
.bin("trunk-analytics-cli")
.target_dir(CARGO_MANIFEST_DIR.join("../target"))
.manifest_path(CARGO_MANIFEST_DIR.join("../cli/Cargo.toml"))
.features("force-sentry-env-dev")
.current_release()
.current_target()
.run()
.unwrap();
}

fn generate_mock_git_repo<T: AsRef<Path>>(directory: T) {
setup_repo_with_commit(directory).unwrap();
}

fn generate_mock_junit_xmls<T: AsRef<Path>>(directory: T) {
let mut jm = JunitMock::new(junit_mock::Options::default());
let reports = jm.generate_reports();
JunitMock::write_reports_to_file(directory.as_ref(), reports).unwrap();
}

fn generate_mock_codeowners<T: AsRef<Path>>(directory: T) {
const CODEOWNERS: &str = r#"
[Owners of Everything]
* @user
"#;
fs::write(directory.as_ref().join("CODEOWNERS"), CODEOWNERS).unwrap();
}

// NOTE: must be multi threaded to start a mock server
#[tokio::test(flavor = "multi_thread")]
async fn upload_bundle() {
let temp_dir = tempdir().unwrap();
generate_mock_git_repo(&temp_dir);
generate_mock_junit_xmls(&temp_dir);
generate_mock_valid_junit_xmls(&temp_dir);
generate_mock_codeowners(&temp_dir);

let state = MockServerBuilder::new().spawn_mock_server().await;
Expand Down
Loading

0 comments on commit 2fea36d

Please sign in to comment.