Skip to content
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 GitHub”, 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

[TRUNK-12978] v1 validate command #129

Merged
merged 9 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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() {}
50 changes: 6 additions & 44 deletions cli-tests/src/upload.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,28 @@
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,
mock_server::{spawn_mock_server, RequestPayload},
};
use test_utils::mock_server::{spawn_mock_server, RequestPayload};
use trunk_analytics_cli::{
codeowners::CodeOwners,
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 = spawn_mock_server().await;
Expand Down
Loading
Loading