From dc499b14344dbd660e69e56d6ce806e5170260f7 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 14 Apr 2023 13:27:16 +0200 Subject: [PATCH] Add command `sentry-cli debug-files bundle-jvm` for bundling Java (and other JVM based languages) sources (#1551) --- src/commands/debug_files/bundle_jvm.rs | 110 ++++++++++++++++++ src/commands/debug_files/find.rs | 1 + src/commands/debug_files/mod.rs | 2 + src/commands/debug_files/upload.rs | 1 + src/utils/dif.rs | 6 + src/utils/file_upload.rs | 16 ++- .../debug_files-bundle-jvm-help.trycmd | 26 +++++ ...ug_files-bundle-jvm-input-dir-empty.trycmd | 8 ++ ...ebug_files-bundle-jvm-input-is-file.trycmd | 9 ++ ...ug_files-bundle-jvm-input-not-found.trycmd | 9 ++ ...debug_files-bundle-jvm-invalid-uuid.trycmd | 8 ++ ...bug_files-bundle-jvm-output-is-file.trycmd | 12 ++ ...g_files-bundle-jvm-output-not-found.trycmd | 8 ++ .../debug_files/debug_files-bundle-jvm.trycmd | 8 ++ .../debug_files-upload-help.trycmd | 2 +- .../_cases/upload_dif/upload_dif-help.trycmd | 2 +- .../jvm/io/sentry/sample/MainActivity.java | 4 + .../jvm/io/sentry/sample/SampleActivity.kt | 4 + tests/integration/debug_files/bundle_jvm.rs | 73 ++++++++++++ tests/integration/debug_files/mod.rs | 1 + tests/integration/mod.rs | 61 ++++++++++ tests/integration/sourcemaps/upload.rs | 67 +---------- 22 files changed, 370 insertions(+), 68 deletions(-) create mode 100644 src/commands/debug_files/bundle_jvm.rs create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-help.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-is-file.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-not-found.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-not-found.trycmd create mode 100644 tests/integration/_cases/debug_files/debug_files-bundle-jvm.trycmd create mode 100644 tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java create mode 100644 tests/integration/_fixtures/jvm/io/sentry/sample/SampleActivity.kt create mode 100644 tests/integration/debug_files/bundle_jvm.rs diff --git a/src/commands/debug_files/bundle_jvm.rs b/src/commands/debug_files/bundle_jvm.rs new file mode 100644 index 0000000000..a43f571dfb --- /dev/null +++ b/src/commands/debug_files/bundle_jvm.rs @@ -0,0 +1,110 @@ +use std::fs; +use std::path::{PathBuf}; +use std::str::FromStr; +use anyhow::{bail, Context, Result}; +use clap::{Arg, ArgMatches, Command}; +use sentry::types::DebugId; +use symbolic::debuginfo::sourcebundle::{SourceFileType}; +use crate::api::Api; +use crate::config::Config; +use crate::utils::args::ArgExt; +use crate::utils::file_search::ReleaseFileSearch; +use crate::utils::file_upload::{FileUpload, SourceFile, UploadContext}; +use crate::utils::fs::{path_as_url}; + +pub fn make_command(command: Command) -> Command { + command + .hide(true) // experimental for now + .about("Create a source bundle for the given JVM based source files (e.g. Java, Kotlin, ...)") + .org_arg() + .project_arg(false) + .arg( + Arg::new("path") + .value_name("PATH") + .required(true) + .value_parser(clap::builder::PathBufValueParser::new()) + .help("The directory containing source files to bundle."), + ) + .arg( + Arg::new("output") + .long("output") + .value_name("PATH") + .required(true) + .value_parser(clap::builder::PathBufValueParser::new()) + .help("The path to the output folder."), + ) + .arg( + Arg::new("debug_id") + .long("debug-id") + .value_name("UUID") + .required(true) + .value_parser(DebugId::from_str) + .help("Debug ID (UUID) to use for the source bundle."), + ) +} + +pub fn execute(matches: &ArgMatches) -> Result<()> { + let config = Config::current(); + let org = config.get_org(matches)?; + let project = config.get_project(matches).ok(); + let api = Api::current(); + let chunk_upload_options = api.get_chunk_upload_options(&org)?; + let context = &UploadContext { + org: &org, + project: project.as_deref(), + release: None, + dist: None, + note: None, + wait: true, + dedupe: false, + chunk_upload_options: chunk_upload_options.as_ref(), + }; + let path = matches.get_one::("path").unwrap(); + let output_path = matches.get_one::("output").unwrap(); + let debug_id = matches.get_one::("debug_id").unwrap(); + let out = output_path.join(format!("{debug_id}.zip")); + + if !path.exists() { + bail!("Given path does not exist: {}", path.display()) + } + + if !path.is_dir() { + bail!("Given path is not a directory: {}", path.display()) + } + + if !output_path.exists() { + fs::create_dir_all(output_path).context(format!("Failed to create output directory {}", output_path.display()))?; + } + + let sources = ReleaseFileSearch::new(path.to_path_buf()).collect_files()?; + let files = sources + .iter() + .map(|source| { + let local_path = source.path.strip_prefix(&source.base_path).unwrap(); + let local_path_jvm_ext = local_path.with_extension("jvm"); + let url = format!("~/{}", path_as_url(&local_path_jvm_ext)); + ( + url.to_string(), + SourceFile { + url, + path: source.path.clone(), + contents: source.contents.clone(), + ty: SourceFileType::Source, + headers: vec![], + messages: vec![], + already_uploaded: false, + }, + ) + }) + .collect(); + + let tempfile = FileUpload::new(context) + .files(&files) + .build_jvm_bundle(Some(*debug_id)) + .context("Unable to create source bundle")?; + + fs::copy(tempfile.path(), &out).context("Unable to write source bundle")?; + println!("Created {}", out.display()); + + Ok(()) +} diff --git a/src/commands/debug_files/find.rs b/src/commands/debug_files/find.rs index b2c196a10e..940989a3bd 100644 --- a/src/commands/debug_files/find.rs +++ b/src/commands/debug_files/find.rs @@ -149,6 +149,7 @@ fn find_ids( DifType::SourceBundle => find_ids_for_sourcebundle(&dirent, &remaining), DifType::Breakpad => find_ids_for_breakpad(&dirent, &remaining), DifType::Proguard => find_ids_for_proguard(&dirent, &proguard_uuids), + DifType::Jvm => find_ids_for_sourcebundle(&dirent, &remaining), DifType::Wasm => None, }) .flatten() diff --git a/src/commands/debug_files/mod.rs b/src/commands/debug_files/mod.rs index 7464550855..dd692c1760 100644 --- a/src/commands/debug_files/mod.rs +++ b/src/commands/debug_files/mod.rs @@ -1,6 +1,7 @@ use anyhow::Result; use clap::{ArgMatches, Command}; +pub mod bundle_jvm; pub mod bundle_sources; pub mod check; pub mod find; @@ -11,6 +12,7 @@ macro_rules! each_subcommand { ($mac:ident) => { $mac!(bundle_sources); $mac!(check); + $mac!(bundle_jvm); $mac!(find); $mac!(print_sources); $mac!(upload); diff --git a/src/commands/debug_files/upload.rs b/src/commands/debug_files/upload.rs index a3eb23729c..14b8106915 100644 --- a/src/commands/debug_files/upload.rs +++ b/src/commands/debug_files/upload.rs @@ -234,6 +234,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { "pe" => upload.filter_format(DifFormat::Object(FileFormat::Pe)), "sourcebundle" => upload.filter_format(DifFormat::Object(FileFormat::SourceBundle)), "portablepdb" => upload.filter_format(DifFormat::Object(FileFormat::PortablePdb)), + "jvm" => upload.filter_format(DifFormat::Object(FileFormat::SourceBundle)), "bcsymbolmap" => { upload.filter_format(DifFormat::BcSymbolMap); upload.filter_format(DifFormat::PList) diff --git a/src/utils/dif.rs b/src/utils/dif.rs index c120b034b3..7c359a073f 100644 --- a/src/utils/dif.rs +++ b/src/utils/dif.rs @@ -21,6 +21,7 @@ pub enum DifType { Pdb, PortablePdb, Wasm, + Jvm, } impl DifType { @@ -35,6 +36,7 @@ impl DifType { DifType::Breakpad => "breakpad", DifType::Proguard => "proguard", DifType::Wasm => "wasm", + DifType::Jvm => "jvm", } } @@ -49,6 +51,7 @@ impl DifType { DifType::Breakpad, DifType::Proguard, DifType::Wasm, + DifType::Jvm, ] } @@ -63,6 +66,7 @@ impl DifType { "breakpad", "proguard", "wasm", + "jvm", ] } } @@ -87,6 +91,7 @@ impl str::FromStr for DifType { "breakpad" => Ok(DifType::Breakpad), "proguard" => Ok(DifType::Proguard), "wasm" => Ok(DifType::Wasm), + "jvm" => Ok(DifType::Jvm), _ => bail!("Invalid debug info file type"), } } @@ -251,6 +256,7 @@ impl DifFile<'static> { Some(DifType::Wasm) => DifFile::open_object(path, FileFormat::Wasm), Some(DifType::Breakpad) => DifFile::open_object(path, FileFormat::Breakpad), Some(DifType::Proguard) => DifFile::open_proguard(path), + Some(DifType::Jvm) => DifFile::open_object(path, FileFormat::SourceBundle), None => DifFile::try_open(path), } } diff --git a/src/utils/file_upload.rs b/src/utils/file_upload.rs index 61136aa4b8..bea124c9ba 100644 --- a/src/utils/file_upload.rs +++ b/src/utils/file_upload.rs @@ -188,6 +188,10 @@ impl<'a> FileUpload<'a> { .map_or(DEFAULT_CONCURRENCY, |o| usize::from(o.concurrency)); upload_files_parallel(self.context, &self.files, concurrency) } + + pub fn build_jvm_bundle(&self, debug_id: Option) -> Result { + build_artifact_bundle(self.context, &self.files, debug_id) + } } fn upload_files_parallel( @@ -274,7 +278,7 @@ fn upload_files_chunked( files: &SourceFiles, options: &ChunkUploadOptions, ) -> Result<()> { - let archive = build_artifact_bundle(context, files)?; + let archive = build_artifact_bundle(context, files, None)?; let progress_style = ProgressStyle::default_spinner().template("{spinner} Optimizing bundle for upload..."); @@ -396,7 +400,11 @@ fn build_debug_id(files: &SourceFiles) -> DebugId { DebugId::from_uuid(uuid::Builder::from_sha1_bytes(sha1_bytes).into_uuid()) } -fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result { +fn build_artifact_bundle( + context: &UploadContext, + files: &SourceFiles, + debug_id: Option, +) -> Result { let progress_style = ProgressStyle::default_bar().template( "{prefix:.dim} Bundling files for upload... {msg:.dim}\ \n{wide_bar} {pos}/{len}", @@ -410,7 +418,9 @@ fn build_artifact_bundle(context: &UploadContext, files: &SourceFiles) -> Result let mut bundle = SourceBundleWriter::start(BufWriter::new(archive.open()?))?; // artifact bundles get a random UUID as debug id - bundle.set_attribute("debug_id", build_debug_id(files).to_string()); + let debug_id = debug_id.unwrap_or_else(|| build_debug_id(files)); + bundle.set_attribute("debug_id", debug_id.to_string()); + if let Some(note) = context.note { bundle.set_attribute("note", note.to_owned()); } diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-help.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-help.trycmd new file mode 100644 index 0000000000..f2fd106357 --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-help.trycmd @@ -0,0 +1,26 @@ +``` +$ sentry-cli debug-files bundle-jvm --help +? success +Create a source bundle for the given JVM based source files (e.g. Java, Kotlin, ...) + +Usage: sentry-cli[EXE] debug-files bundle-jvm [OPTIONS] --output --debug-id + +Arguments: + The directory containing source files to bundle. + +Options: + -o, --org The organization slug + --header Custom headers that should be attached to all requests + in key:value format. + -p, --project The project slug. + --auth-token Use the given Sentry auth token. + --output The path to the output folder. + --debug-id Debug ID (UUID) to use for the source bundle. + --log-level Set the log output verbosity. [possible values: trace, debug, info, + warn, error] + --quiet Do not print any output while preserving correct exit code. This + flag is currently implemented only for selected subcommands. + [aliases: silent] + -h, --help Print help + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd new file mode 100644 index 0000000000..eac95571b4 --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd @@ -0,0 +1,8 @@ +``` +$ sentry-cli debug-files bundle-jvm --output . --debug-id 48dee70b-4f3f-4a49-9223-de441738f7cd empty-dir +? success +> Found 0 files +> Bundled 0 files for upload +Created ./48dee70b-4f3f-4a49-9223-de441738f7cd.zip + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-is-file.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-is-file.trycmd new file mode 100644 index 0000000000..a4510d1edc --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-is-file.trycmd @@ -0,0 +1,9 @@ +``` +$ sentry-cli debug-files bundle-jvm --output `cwd` --debug-id 59144E0E-52C4-41F8-9111-0D6F8F14905B tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java +? failed +error: Given path is not a directory: tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-not-found.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-not-found.trycmd new file mode 100644 index 0000000000..61cd9aa268 --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-not-found.trycmd @@ -0,0 +1,9 @@ +``` +$ sentry-cli debug-files bundle-jvm --output `cwd` --debug-id 7A575F05-0585-4DB0-95DE-D0C032D7C707 tests/integration/_fixtures/i-do-not-exist +? failed +error: Given path does not exist: tests/integration/_fixtures/i-do-not-exist + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd new file mode 100644 index 0000000000..35e4097cf2 --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd @@ -0,0 +1,8 @@ +``` +$ sentry-cli debug-files bundle-jvm --output . --debug-id not-a-valid-uuid io +? failed +error: invalid value 'not-a-valid-uuid' for '--debug-id ': invalid debug identifier + +For more information, try '--help'. + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.trycmd new file mode 100644 index 0000000000..aa3c0ebb6a --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.trycmd @@ -0,0 +1,12 @@ +``` +$ sentry-cli debug-files bundle-jvm --output ./file.txt --debug-id D384DC3B-AB2F-4DC7-903D-2C851E27E094 ./io +? failed +> Found 2 files +> Bundled 2 files for upload +error: Unable to write source bundle + caused by: [..] + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-not-found.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-not-found.trycmd new file mode 100644 index 0000000000..a9f3c8ab86 --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-not-found.trycmd @@ -0,0 +1,8 @@ +``` +$ sentry-cli debug-files bundle-jvm --output i-do-not-exist --debug-id 0B693ABA-531C-4EB6-99E4-B7320C3C85DA tests/integration/_fixtures/jvm +? success +> Found 2 files +> Bundled 2 files for upload +Created i-do-not-exist/0b693aba-531c-4eb6-99e4-b7320c3c85da.zip + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-bundle-jvm.trycmd b/tests/integration/_cases/debug_files/debug_files-bundle-jvm.trycmd new file mode 100644 index 0000000000..7dc48fce3b --- /dev/null +++ b/tests/integration/_cases/debug_files/debug_files-bundle-jvm.trycmd @@ -0,0 +1,8 @@ +``` +$ sentry-cli debug-files bundle-jvm --output . --debug-id a4368a48-0880-40d7-9a26-c9ef5a84d156 ./io +? success +> Found 2 files +> Bundled 2 files for upload +Created ./a4368a48-0880-40d7-9a26-c9ef5a84d156.zip + +``` diff --git a/tests/integration/_cases/debug_files/debug_files-upload-help.trycmd b/tests/integration/_cases/debug_files/debug_files-upload-help.trycmd index 805cb00941..2e63564171 100644 --- a/tests/integration/_cases/debug_files/debug_files-upload-help.trycmd +++ b/tests/integration/_cases/debug_files/debug_files-upload-help.trycmd @@ -17,7 +17,7 @@ Options: -t, --type Only consider debug information files of the given type. By default, all types are considered. [possible values: bcsymbolmap, dsym, elf, pe, pdb, portablepdb, sourcebundle, breakpad, proguard, - wasm] + wasm, jvm] --no-unwind Do not scan for stack unwinding information. Specify this flag for builds with disabled FPO, or when stackwalking occurs on the device. This usually excludes executables and dynamic libraries. diff --git a/tests/integration/_cases/upload_dif/upload_dif-help.trycmd b/tests/integration/_cases/upload_dif/upload_dif-help.trycmd index 2ebaebaba9..f94c279186 100644 --- a/tests/integration/_cases/upload_dif/upload_dif-help.trycmd +++ b/tests/integration/_cases/upload_dif/upload_dif-help.trycmd @@ -17,7 +17,7 @@ Options: -t, --type Only consider debug information files of the given type. By default, all types are considered. [possible values: bcsymbolmap, dsym, elf, pe, pdb, portablepdb, sourcebundle, breakpad, proguard, - wasm] + wasm, jvm] --no-unwind Do not scan for stack unwinding information. Specify this flag for builds with disabled FPO, or when stackwalking occurs on the device. This usually excludes executables and dynamic libraries. diff --git a/tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java b/tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java new file mode 100644 index 0000000000..a32b15846a --- /dev/null +++ b/tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java @@ -0,0 +1,4 @@ +package integration._fixtures.jvm.io.sentry.sample; + +public class MainActivity { +} diff --git a/tests/integration/_fixtures/jvm/io/sentry/sample/SampleActivity.kt b/tests/integration/_fixtures/jvm/io/sentry/sample/SampleActivity.kt new file mode 100644 index 0000000000..5d3940d35e --- /dev/null +++ b/tests/integration/_fixtures/jvm/io/sentry/sample/SampleActivity.kt @@ -0,0 +1,4 @@ +package integration._fixtures.jvm.io.sentry.sample + +class SampleActivity { +} diff --git a/tests/integration/debug_files/bundle_jvm.rs b/tests/integration/debug_files/bundle_jvm.rs new file mode 100644 index 0000000000..a36f013ba9 --- /dev/null +++ b/tests/integration/debug_files/bundle_jvm.rs @@ -0,0 +1,73 @@ +use crate::integration::{ + copy_recursively, mock_common_upload_endpoints, register_test, ServerBehavior, +}; +use std::fs::{create_dir, remove_dir_all, write}; + +#[test] +fn command_bundle_jvm_help() { + register_test("debug_files/debug_files-bundle-jvm-help.trycmd"); +} + +#[test] +fn command_bundle_jvm_out_not_found_creates_dir() { + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm-output-not-found.trycmd"); +} + +#[test] +fn command_bundle_jvm_fails_out_is_file() { + let testcase_cwd = + "tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.in/"; + let testcase_cwd_path = std::path::Path::new(testcase_cwd); + if testcase_cwd_path.exists() { + remove_dir_all(testcase_cwd_path).unwrap(); + } + copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap(); + write(testcase_cwd_path.join("file.txt"), "some file content").unwrap(); + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + + register_test("debug_files/debug_files-bundle-jvm-output-is-file.trycmd"); +} + +#[test] +fn command_bundle_jvm_fails_input_not_found() { + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm-input-not-found.trycmd"); +} + +#[test] +fn command_bundle_jvm_fails_input_is_file() { + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm-input-is-file.trycmd"); +} + +#[test] +fn command_bundle_jvm_input_dir_empty() { + let testcase_cwd = + "tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.in/"; + let testcase_cwd_path = std::path::Path::new(testcase_cwd); + if testcase_cwd_path.exists() { + remove_dir_all(testcase_cwd_path).unwrap(); + } + copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap(); + create_dir(testcase_cwd_path.join("empty-dir")).unwrap(); + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd"); +} + +#[test] +fn command_bundle_jvm_fails_invalid_uuid() { + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd"); +} + +#[test] +fn command_bundle_jvm() { + let testcase_cwd_path = "tests/integration/_cases/debug_files/debug_files-bundle-jvm.in/"; + if std::path::Path::new(testcase_cwd_path).exists() { + remove_dir_all(testcase_cwd_path).unwrap(); + } + copy_recursively("tests/integration/_fixtures/jvm/", testcase_cwd_path).unwrap(); + let _upload_endpoints = mock_common_upload_endpoints(ServerBehavior::Legacy); + register_test("debug_files/debug_files-bundle-jvm.trycmd"); +} diff --git a/tests/integration/debug_files/mod.rs b/tests/integration/debug_files/mod.rs index a6c5baf0fe..9c9d24f4c0 100644 --- a/tests/integration/debug_files/mod.rs +++ b/tests/integration/debug_files/mod.rs @@ -1,5 +1,6 @@ use crate::integration::register_test; +mod bundle_jvm; mod bundle_sources; mod check; mod print_sources; diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index 07c849215b..48a27feebf 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -115,3 +115,64 @@ pub fn copy_recursively(source: impl AsRef, destination: impl AsRef) } Ok(()) } + +pub enum ServerBehavior { + Legacy, + Modern, +} + +// Endpoints need to be bound, as they need to live long enough for test to finish +pub fn mock_common_upload_endpoints(behavior: ServerBehavior) -> Vec { + let (accept, release_request_count, assemble_endpoint) = match behavior { + ServerBehavior::Legacy => ( + "\"release_files\"", + 2, + "/api/0/organizations/wat-org/releases/wat-release/assemble/", + ), + ServerBehavior::Modern => ( + "\"release_files\", \"artifact_bundles\"", + 0, + "/api/0/organizations/wat-org/artifactbundle/assemble/", + ), + }; + let chunk_upload_response = format!( + "{{ + \"url\": \"{}/api/0/organizations/wat-org/chunk-upload/\", + \"chunkSize\": 8388608, + \"chunksPerRequest\": 64, + \"maxRequestSize\": 33554432, + \"concurrency\": 8, + \"hashAlgorithm\": \"sha1\", + \"accept\": [{}] + }}", + server_url(), + accept, + ); + + vec![ + mock_endpoint( + EndpointOptions::new("POST", "/api/0/projects/wat-org/wat-project/releases/", 208) + .with_response_file("releases/get-release.json"), + ) + .expect_at_least(release_request_count) + .expect_at_most(release_request_count), + mock_endpoint( + EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200) + .with_response_body(chunk_upload_response), + ), + mock_endpoint( + EndpointOptions::new("POST", "/api/0/organizations/wat-org/chunk-upload/", 200) + .with_response_body("[]"), + ), + mock_endpoint( + EndpointOptions::new("POST", assemble_endpoint, 200) + .with_response_body(r#"{"state":"created","missingChunks":[]}"#), + ), + ] +} + +pub fn assert_endpoints(mocks: &[Mock]) { + for mock in mocks { + mock.assert(); + } +} diff --git a/tests/integration/sourcemaps/upload.rs b/tests/integration/sourcemaps/upload.rs index 5dcc227077..66c3ff35ac 100644 --- a/tests/integration/sourcemaps/upload.rs +++ b/tests/integration/sourcemaps/upload.rs @@ -1,66 +1,7 @@ -use crate::integration::{mock_endpoint, register_test, EndpointOptions}; -use mockito::{server_url, Mock}; - -enum ServerBehavior { - Legacy, - Modern, -} - -// Endpoints need to be bound, as they need to live long enough for test to finish -fn mock_common_upload_endpoints(behavior: ServerBehavior) -> Vec { - let (accept, release_request_count, assemble_endpoint) = match behavior { - ServerBehavior::Legacy => ( - "\"release_files\"", - 2, - "/api/0/organizations/wat-org/releases/wat-release/assemble/", - ), - ServerBehavior::Modern => ( - "\"release_files\", \"artifact_bundles\"", - 0, - "/api/0/organizations/wat-org/artifactbundle/assemble/", - ), - }; - let chunk_upload_response = format!( - "{{ - \"url\": \"{}/api/0/organizations/wat-org/chunk-upload/\", - \"chunkSize\": 8388608, - \"chunksPerRequest\": 64, - \"maxRequestSize\": 33554432, - \"concurrency\": 8, - \"hashAlgorithm\": \"sha1\", - \"accept\": [{}] - }}", - server_url(), - accept, - ); - - vec![ - mock_endpoint( - EndpointOptions::new("POST", "/api/0/projects/wat-org/wat-project/releases/", 208) - .with_response_file("releases/get-release.json"), - ) - .expect_at_least(release_request_count) - .expect_at_most(release_request_count), - mock_endpoint( - EndpointOptions::new("GET", "/api/0/organizations/wat-org/chunk-upload/", 200) - .with_response_body(chunk_upload_response), - ), - mock_endpoint( - EndpointOptions::new("POST", "/api/0/organizations/wat-org/chunk-upload/", 200) - .with_response_body("[]"), - ), - mock_endpoint( - EndpointOptions::new("POST", assemble_endpoint, 200) - .with_response_body(r#"{"state":"created","missingChunks":[]}"#), - ), - ] -} - -fn assert_endpoints(mocks: &[Mock]) { - for mock in mocks { - mock.assert(); - } -} +use crate::integration::{ + assert_endpoints, mock_common_upload_endpoints, mock_endpoint, register_test, EndpointOptions, + ServerBehavior, +}; #[test] fn command_sourcemaps_upload_help() {