diff --git a/core/src/lib.rs b/core/src/lib.rs index 32faed5..b3dacc3 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -5,3 +5,6 @@ pub mod report; pub mod parsers; pub mod error; + +#[cfg(any(test, feature = "testing"))] +mod test_utils; diff --git a/core/src/parsers/pyreport/chunks.rs b/core/src/parsers/pyreport/chunks.rs index 4aea41b..74e1594 100644 --- a/core/src/parsers/pyreport/chunks.rs +++ b/core/src/parsers/pyreport/chunks.rs @@ -555,9 +555,9 @@ mod tests { use winnow::error::AddContext; use super::*; - use crate::report::{ - models::*, - test::{TestReport, TestReportBuilder}, + use crate::{ + report::models::*, + test_utils::test_report::{TestReport, TestReportBuilder}, }; type TestStream<'a> = ReportOutputStream<&'a str, TestReport, TestReportBuilder>; diff --git a/core/src/parsers/pyreport/report_json.rs b/core/src/parsers/pyreport/report_json.rs index 4a03070..f9a24e0 100644 --- a/core/src/parsers/pyreport/report_json.rs +++ b/core/src/parsers/pyreport/report_json.rs @@ -267,7 +267,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::report::test::TestReportBuilder; + use crate::test_utils::test_report::TestReportBuilder; #[test] fn test_report_json_simple_valid_case() { diff --git a/core/src/parsers/pyreport/utils.rs b/core/src/parsers/pyreport/utils.rs index ae5e9c6..fd76b1e 100644 --- a/core/src/parsers/pyreport/utils.rs +++ b/core/src/parsers/pyreport/utils.rs @@ -312,7 +312,7 @@ mod tests { use std::collections::HashMap; use super::*; - use crate::report::test::{TestReport, TestReportBuilder}; + use crate::test_utils::test_report::{TestReport, TestReportBuilder}; struct Ctx { parse_ctx: ParseCtx, diff --git a/core/src/report/mod.rs b/core/src/report/mod.rs index 1d924a6..9ecfce4 100644 --- a/core/src/report/mod.rs +++ b/core/src/report/mod.rs @@ -6,9 +6,6 @@ pub use sqlite::{SqliteReport, SqliteReportBuilder, SqliteReportBuilderTx}; #[cfg(feature = "pyreport")] pub mod pyreport; -#[cfg(any(test, feature = "testing"))] -pub mod test; - use crate::error::Result; /// An interface for coverage data. diff --git a/core/src/report/pyreport/chunks.rs b/core/src/report/pyreport/chunks.rs index ecfd3ce..5c86708 100644 --- a/core/src/report/pyreport/chunks.rs +++ b/core/src/report/pyreport/chunks.rs @@ -313,16 +313,11 @@ pub fn sql_to_chunks(report: &SqliteReport, output: &mut impl Write) -> Result<( #[cfg(test)] mod tests { - use std::path::PathBuf; - use serde_json::json; use tempfile::TempDir; use super::*; - use crate::report::{ - sqlite::{Insertable, SqliteReportBuilder}, - ReportBuilder, - }; + use crate::test_utils::sqlite_report::build_sample_report; struct Ctx { temp_dir: TempDir, @@ -334,264 +329,6 @@ mod tests { } } - fn build_sample_report(path: PathBuf) -> Result { - let mut builder = SqliteReportBuilder::new(path)?; - let file_1 = builder.insert_file("src/report/report.rs")?; - let file_2 = builder.insert_file("src/report/models.rs")?; - - let upload_1 = models::RawUpload { - id: 5, - timestamp: Some(123), - raw_upload_url: Some("upload 1 url".to_string()), - flags: Some(json!(["flag on upload 1"])), - provider: Some("provider upload 1".to_string()), - build: Some("build upload 1".to_string()), - name: Some("name upload 1".to_string()), - job_name: Some("job name upload 1".to_string()), - ci_run_url: Some("ci run url upload 1".to_string()), - state: Some("state upload 1".to_string()), - env: Some("env upload 1".to_string()), - session_type: Some("type upload 1".to_string()), - session_extras: Some(json!({"k1": "v1"})), - ..Default::default() - }; - // Insert directly, not through report builder, because we don't want a random - // ID - upload_1.insert(&builder.conn)?; - - let upload_2 = models::RawUpload { - id: 10, - timestamp: Some(456), - raw_upload_url: Some("upload 2 url".to_string()), - flags: Some(json!(["flag on upload 2"])), - provider: Some("provider upload 2".to_string()), - build: Some("build upload 2".to_string()), - name: Some("name upload 2".to_string()), - job_name: Some("job name upload 2".to_string()), - ci_run_url: Some("ci run url upload 2".to_string()), - state: Some("state upload 2".to_string()), - env: Some("env upload 2".to_string()), - session_type: Some("type upload 2".to_string()), - session_extras: Some(json!({"k2": "v2"})), - ..Default::default() - }; - // Insert directly, not through report builder, because we don't want a random - // ID - upload_2.insert(&builder.conn)?; - - let line_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 1, - coverage_type: models::CoverageType::Line, - hits: Some(3), - ..Default::default() - })?; - - let line_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 1, - coverage_type: models::CoverageType::Line, - hits: Some(4), - ..Default::default() - })?; - let _line_3 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_2.id, - source_file_id: file_2.id, - line_no: 3, - coverage_type: models::CoverageType::Line, - hits: Some(0), - ..Default::default() - })?; - - let branch_sample_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 3, - coverage_type: models::CoverageType::Branch, - hit_branches: Some(2), - total_branches: Some(2), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_1.source_file_id, - local_sample_id: branch_sample_1.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "0:jump".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_1.source_file_id, - local_sample_id: branch_sample_1.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "1".to_string(), - ..Default::default() - })?; - - let branch_sample_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 6, - coverage_type: models::CoverageType::Branch, - hit_branches: Some(2), - total_branches: Some(4), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "0:jump".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "1".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 0, - branch_format: models::BranchFormat::Condition, - branch: "2".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 0, - branch_format: models::BranchFormat::Condition, - branch: "3".to_string(), - ..Default::default() - })?; - - let method_sample_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 2, - coverage_type: models::CoverageType::Method, - hits: Some(2), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_1.id, - source_file_id: method_sample_1.source_file_id, - local_sample_id: method_sample_1.local_sample_id, - line_no: Some(method_sample_1.line_no), - hit_branches: Some(2), - total_branches: Some(4), - hit_complexity_paths: Some(2), - total_complexity: Some(4), - ..Default::default() - })?; - - let method_sample_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 2, - coverage_type: models::CoverageType::Method, - hits: Some(5), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_1.id, - source_file_id: method_sample_2.source_file_id, - local_sample_id: method_sample_2.local_sample_id, - line_no: Some(method_sample_2.line_no), - hit_branches: Some(2), - total_branches: Some(4), - ..Default::default() - })?; - - let method_sample_3 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_2.id, - source_file_id: file_2.id, - line_no: 5, - coverage_type: models::CoverageType::Method, - hits: Some(0), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_2.id, - source_file_id: method_sample_3.source_file_id, - local_sample_id: method_sample_3.local_sample_id, - line_no: Some(method_sample_3.line_no), - hit_complexity_paths: Some(2), - total_complexity: Some(4), - ..Default::default() - })?; - - let line_with_partial_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 8, - coverage_type: models::CoverageType::Line, - hits: Some(3), - ..Default::default() - })?; - let _ = builder.insert_span_data(models::SpanData { - raw_upload_id: upload_1.id, - source_file_id: line_with_partial_1.source_file_id, - local_sample_id: Some(line_with_partial_1.local_sample_id), - start_line: Some(line_with_partial_1.line_no), - start_col: Some(3), - end_line: Some(line_with_partial_1.line_no), - end_col: None, - hits: 3, - ..Default::default() - })?; - - let label_1 = builder.insert_context("test-case")?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_1.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_1.local_sample_id), - ..Default::default() - })?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_1.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_2.local_sample_id), - ..Default::default() - })?; - - let label_2 = builder.insert_context("test-case 2")?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_2.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_1.local_sample_id), - ..Default::default() - })?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_2.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_2.local_sample_id), - ..Default::default() - })?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_2.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(method_sample_1.local_sample_id), - ..Default::default() - })?; - - builder.build() - } - #[test] fn test_array_without_trailing_nulls() { assert_eq!( diff --git a/core/src/report/pyreport/report_json.rs b/core/src/report/pyreport/report_json.rs index 3185795..b6df657 100644 --- a/core/src/report/pyreport/report_json.rs +++ b/core/src/report/pyreport/report_json.rs @@ -237,16 +237,11 @@ pub fn sql_to_report_json(report: &SqliteReport, output: &mut impl Write) -> Res #[cfg(test)] mod tests { - use std::path::PathBuf; - use serde_json::json; use tempfile::TempDir; use super::*; - use crate::report::{ - sqlite::{Insertable, SqliteReportBuilder}, - ReportBuilder, - }; + use crate::test_utils::sqlite_report::build_sample_report; struct Ctx { temp_dir: TempDir, @@ -258,244 +253,6 @@ mod tests { } } - fn build_sample_report(path: PathBuf) -> Result { - let mut builder = SqliteReportBuilder::new(path)?; - let file_1 = builder.insert_file("src/report/report.rs")?; - let file_2 = builder.insert_file("src/report/models.rs")?; - - let upload_1 = models::RawUpload { - id: 5, - timestamp: Some(123), - raw_upload_url: Some("upload 1 url".to_string()), - flags: Some(json!(["flag on upload 1"])), - provider: Some("provider upload 1".to_string()), - build: Some("build upload 1".to_string()), - name: Some("name upload 1".to_string()), - job_name: Some("job name upload 1".to_string()), - ci_run_url: Some("ci run url upload 1".to_string()), - state: Some("state upload 1".to_string()), - env: Some("env upload 1".to_string()), - session_type: Some("type upload 1".to_string()), - session_extras: Some(json!({"k1": "v1"})), - ..Default::default() - }; - // Insert directly, not through report builder, because we don't want a random - // ID - upload_1.insert(&builder.conn)?; - - let upload_2 = models::RawUpload { - id: 10, - timestamp: Some(456), - raw_upload_url: Some("upload 2 url".to_string()), - flags: Some(json!(["flag on upload 2"])), - provider: Some("provider upload 2".to_string()), - build: Some("build upload 2".to_string()), - name: Some("name upload 2".to_string()), - job_name: Some("job name upload 2".to_string()), - ci_run_url: Some("ci run url upload 2".to_string()), - state: Some("state upload 2".to_string()), - env: Some("env upload 2".to_string()), - session_type: Some("type upload 2".to_string()), - session_extras: Some(json!({"k2": "v2"})), - ..Default::default() - }; - // Insert directly, not through report builder, because we don't want a random - // ID - upload_2.insert(&builder.conn)?; - - let line_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 1, - coverage_type: models::CoverageType::Line, - hits: Some(3), - ..Default::default() - })?; - - let line_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 1, - coverage_type: models::CoverageType::Line, - hits: Some(4), - ..Default::default() - })?; - let _line_3 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_2.id, - source_file_id: file_2.id, - line_no: 3, - coverage_type: models::CoverageType::Line, - hits: Some(0), - ..Default::default() - })?; - - let branch_sample_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 3, - coverage_type: models::CoverageType::Branch, - hit_branches: Some(2), - total_branches: Some(2), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_1.source_file_id, - local_sample_id: branch_sample_1.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "0:jump".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_1.source_file_id, - local_sample_id: branch_sample_1.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "1".to_string(), - ..Default::default() - })?; - - let branch_sample_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 6, - coverage_type: models::CoverageType::Branch, - hit_branches: Some(2), - total_branches: Some(4), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "0:jump".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 1, - branch_format: models::BranchFormat::Condition, - branch: "1".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 0, - branch_format: models::BranchFormat::Condition, - branch: "2".to_string(), - ..Default::default() - })?; - let _ = builder.insert_branches_data(models::BranchesData { - raw_upload_id: upload_1.id, - source_file_id: branch_sample_2.source_file_id, - local_sample_id: branch_sample_2.local_sample_id, - hits: 0, - branch_format: models::BranchFormat::Condition, - branch: "3".to_string(), - ..Default::default() - })?; - - let method_sample_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 2, - coverage_type: models::CoverageType::Method, - hits: Some(2), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_1.id, - source_file_id: method_sample_1.source_file_id, - local_sample_id: method_sample_1.local_sample_id, - line_no: Some(method_sample_1.line_no), - hit_branches: Some(2), - total_branches: Some(4), - hit_complexity_paths: Some(2), - total_complexity: Some(4), - ..Default::default() - })?; - - let method_sample_2 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_2.id, - line_no: 2, - coverage_type: models::CoverageType::Method, - hits: Some(5), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_1.id, - source_file_id: method_sample_2.source_file_id, - local_sample_id: method_sample_2.local_sample_id, - line_no: Some(method_sample_2.line_no), - hit_branches: Some(2), - total_branches: Some(4), - ..Default::default() - })?; - - let method_sample_3 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_2.id, - source_file_id: file_2.id, - line_no: 5, - coverage_type: models::CoverageType::Method, - hits: Some(0), - ..Default::default() - })?; - let _ = builder.insert_method_data(models::MethodData { - raw_upload_id: upload_2.id, - source_file_id: method_sample_3.source_file_id, - local_sample_id: method_sample_3.local_sample_id, - line_no: Some(method_sample_3.line_no), - hit_complexity_paths: Some(2), - total_complexity: Some(4), - ..Default::default() - })?; - - let line_with_partial_1 = builder.insert_coverage_sample(models::CoverageSample { - raw_upload_id: upload_1.id, - source_file_id: file_1.id, - line_no: 8, - coverage_type: models::CoverageType::Line, - hits: Some(3), - ..Default::default() - })?; - let _ = builder.insert_span_data(models::SpanData { - raw_upload_id: upload_1.id, - source_file_id: line_with_partial_1.source_file_id, - local_sample_id: Some(line_with_partial_1.local_sample_id), - start_line: Some(line_with_partial_1.line_no), - start_col: Some(3), - end_line: Some(line_with_partial_1.line_no), - end_col: None, - hits: 3, - ..Default::default() - })?; - - let label_1 = builder.insert_context("test-case")?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_1.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_1.local_sample_id), - ..Default::default() - })?; - let _ = builder.associate_context(models::ContextAssoc { - context_id: label_1.id, - raw_upload_id: upload_1.id, - local_sample_id: Some(line_2.local_sample_id), - ..Default::default() - })?; - - builder.build() - } - #[test] fn test_calculate_coverage_pct() { assert_eq!(calculate_coverage_pct(0, 16), "0".to_string()); diff --git a/core/src/test_utils/mod.rs b/core/src/test_utils/mod.rs new file mode 100644 index 0000000..a6523a5 --- /dev/null +++ b/core/src/test_utils/mod.rs @@ -0,0 +1,2 @@ +pub mod sqlite_report; +pub mod test_report; diff --git a/core/src/test_utils/sqlite_report.rs b/core/src/test_utils/sqlite_report.rs new file mode 100644 index 0000000..63491ba --- /dev/null +++ b/core/src/test_utils/sqlite_report.rs @@ -0,0 +1,266 @@ +use std::path::PathBuf; + +use serde_json::json; + +use crate::{ + error::Result, + report::{models, sqlite::Insertable, ReportBuilder, SqliteReport, SqliteReportBuilder}, +}; + +pub fn build_sample_report(path: PathBuf) -> Result { + let mut builder = SqliteReportBuilder::new(path)?; + let file_1 = builder.insert_file("src/report/report.rs")?; + let file_2 = builder.insert_file("src/report/models.rs")?; + + let upload_1 = models::RawUpload { + id: 5, + timestamp: Some(123), + raw_upload_url: Some("upload 1 url".to_string()), + flags: Some(json!(["flag on upload 1"])), + provider: Some("provider upload 1".to_string()), + build: Some("build upload 1".to_string()), + name: Some("name upload 1".to_string()), + job_name: Some("job name upload 1".to_string()), + ci_run_url: Some("ci run url upload 1".to_string()), + state: Some("state upload 1".to_string()), + env: Some("env upload 1".to_string()), + session_type: Some("type upload 1".to_string()), + session_extras: Some(json!({"k1": "v1"})), + ..Default::default() + }; + // Insert directly, not through report builder, because we don't want a random + // ID + upload_1.insert(&builder.conn)?; + + let upload_2 = models::RawUpload { + id: 10, + timestamp: Some(456), + raw_upload_url: Some("upload 2 url".to_string()), + flags: Some(json!(["flag on upload 2"])), + provider: Some("provider upload 2".to_string()), + build: Some("build upload 2".to_string()), + name: Some("name upload 2".to_string()), + job_name: Some("job name upload 2".to_string()), + ci_run_url: Some("ci run url upload 2".to_string()), + state: Some("state upload 2".to_string()), + env: Some("env upload 2".to_string()), + session_type: Some("type upload 2".to_string()), + session_extras: Some(json!({"k2": "v2"})), + ..Default::default() + }; + // Insert directly, not through report builder, because we don't want a random + // ID + upload_2.insert(&builder.conn)?; + + let line_1 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_1.id, + line_no: 1, + coverage_type: models::CoverageType::Line, + hits: Some(3), + ..Default::default() + })?; + + let line_2 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_2.id, + line_no: 1, + coverage_type: models::CoverageType::Line, + hits: Some(4), + ..Default::default() + })?; + let _line_3 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_2.id, + source_file_id: file_2.id, + line_no: 3, + coverage_type: models::CoverageType::Line, + hits: Some(0), + ..Default::default() + })?; + + let branch_sample_1 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_1.id, + line_no: 3, + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), + total_branches: Some(2), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_1.source_file_id, + local_sample_id: branch_sample_1.local_sample_id, + hits: 1, + branch_format: models::BranchFormat::Condition, + branch: "0:jump".to_string(), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_1.source_file_id, + local_sample_id: branch_sample_1.local_sample_id, + hits: 1, + branch_format: models::BranchFormat::Condition, + branch: "1".to_string(), + ..Default::default() + })?; + + let branch_sample_2 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_2.id, + line_no: 6, + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), + total_branches: Some(4), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_2.source_file_id, + local_sample_id: branch_sample_2.local_sample_id, + hits: 1, + branch_format: models::BranchFormat::Condition, + branch: "0:jump".to_string(), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_2.source_file_id, + local_sample_id: branch_sample_2.local_sample_id, + hits: 1, + branch_format: models::BranchFormat::Condition, + branch: "1".to_string(), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_2.source_file_id, + local_sample_id: branch_sample_2.local_sample_id, + hits: 0, + branch_format: models::BranchFormat::Condition, + branch: "2".to_string(), + ..Default::default() + })?; + let _ = builder.insert_branches_data(models::BranchesData { + raw_upload_id: upload_1.id, + source_file_id: branch_sample_2.source_file_id, + local_sample_id: branch_sample_2.local_sample_id, + hits: 0, + branch_format: models::BranchFormat::Condition, + branch: "3".to_string(), + ..Default::default() + })?; + + let method_sample_1 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_1.id, + line_no: 2, + coverage_type: models::CoverageType::Method, + hits: Some(2), + ..Default::default() + })?; + let _ = builder.insert_method_data(models::MethodData { + raw_upload_id: upload_1.id, + source_file_id: method_sample_1.source_file_id, + local_sample_id: method_sample_1.local_sample_id, + line_no: Some(method_sample_1.line_no), + hit_branches: Some(2), + total_branches: Some(4), + hit_complexity_paths: Some(2), + total_complexity: Some(4), + ..Default::default() + })?; + + let method_sample_2 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_2.id, + line_no: 2, + coverage_type: models::CoverageType::Method, + hits: Some(5), + ..Default::default() + })?; + let _ = builder.insert_method_data(models::MethodData { + raw_upload_id: upload_1.id, + source_file_id: method_sample_2.source_file_id, + local_sample_id: method_sample_2.local_sample_id, + line_no: Some(method_sample_2.line_no), + hit_branches: Some(2), + total_branches: Some(4), + ..Default::default() + })?; + + let method_sample_3 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_2.id, + source_file_id: file_2.id, + line_no: 5, + coverage_type: models::CoverageType::Method, + hits: Some(0), + ..Default::default() + })?; + let _ = builder.insert_method_data(models::MethodData { + raw_upload_id: upload_2.id, + source_file_id: method_sample_3.source_file_id, + local_sample_id: method_sample_3.local_sample_id, + line_no: Some(method_sample_3.line_no), + hit_complexity_paths: Some(2), + total_complexity: Some(4), + ..Default::default() + })?; + + let line_with_partial_1 = builder.insert_coverage_sample(models::CoverageSample { + raw_upload_id: upload_1.id, + source_file_id: file_1.id, + line_no: 8, + coverage_type: models::CoverageType::Line, + hits: Some(3), + ..Default::default() + })?; + let _ = builder.insert_span_data(models::SpanData { + raw_upload_id: upload_1.id, + source_file_id: line_with_partial_1.source_file_id, + local_sample_id: Some(line_with_partial_1.local_sample_id), + start_line: Some(line_with_partial_1.line_no), + start_col: Some(3), + end_line: Some(line_with_partial_1.line_no), + end_col: None, + hits: 3, + ..Default::default() + })?; + + let label_1 = builder.insert_context("test-case")?; + let _ = builder.associate_context(models::ContextAssoc { + context_id: label_1.id, + raw_upload_id: upload_1.id, + local_sample_id: Some(line_1.local_sample_id), + ..Default::default() + })?; + let _ = builder.associate_context(models::ContextAssoc { + context_id: label_1.id, + raw_upload_id: upload_1.id, + local_sample_id: Some(line_2.local_sample_id), + ..Default::default() + })?; + + let label_2 = builder.insert_context("test-case 2")?; + let _ = builder.associate_context(models::ContextAssoc { + context_id: label_2.id, + raw_upload_id: upload_1.id, + local_sample_id: Some(line_1.local_sample_id), + ..Default::default() + })?; + let _ = builder.associate_context(models::ContextAssoc { + context_id: label_2.id, + raw_upload_id: upload_1.id, + local_sample_id: Some(line_2.local_sample_id), + ..Default::default() + })?; + let _ = builder.associate_context(models::ContextAssoc { + context_id: label_2.id, + raw_upload_id: upload_1.id, + local_sample_id: Some(method_sample_1.local_sample_id), + ..Default::default() + })?; + + builder.build() +} diff --git a/core/src/report/test.rs b/core/src/test_utils/test_report.rs similarity index 88% rename from core/src/report/test.rs rename to core/src/test_utils/test_report.rs index 52f796a..5370b4b 100644 --- a/core/src/report/test.rs +++ b/core/src/test_utils/test_report.rs @@ -1,11 +1,13 @@ -use super::{ - models::{ - BranchesData, Context, ContextAssoc, CoverageSample, MethodData, RawUpload, SourceFile, - SpanData, +use crate::{ + error, + report::{ + models::{ + BranchesData, Context, ContextAssoc, CoverageSample, MethodData, RawUpload, + ReportTotals, SourceFile, SpanData, + }, + Report, ReportBuilder, }, - Report, ReportBuilder, }; -use crate::error; #[derive(Default)] pub struct TestReport { @@ -68,7 +70,7 @@ impl Report for TestReport { todo!() } - fn totals(&self) -> error::Result { + fn totals(&self) -> error::Result { todo!() } } @@ -143,18 +145,12 @@ impl ReportBuilder for TestReportBuilder { Ok(()) } - fn associate_context( - &mut self, - assoc: super::models::ContextAssoc, - ) -> error::Result { + fn associate_context(&mut self, assoc: ContextAssoc) -> error::Result { self.report.assocs.push(assoc.clone()); Ok(assoc) } - fn multi_associate_context( - &mut self, - assocs: Vec<&mut super::models::ContextAssoc>, - ) -> error::Result<()> { + fn multi_associate_context(&mut self, assocs: Vec<&mut ContextAssoc>) -> error::Result<()> { self.report .assocs .extend(assocs.into_iter().map(|m| m.clone()));