diff --git a/src/parsers/pyreport_shim/chunks.rs b/src/parsers/pyreport_shim/chunks.rs index f5626b5..1000730 100644 --- a/src/parsers/pyreport_shim/chunks.rs +++ b/src/parsers/pyreport_shim/chunks.rs @@ -744,39 +744,31 @@ mod tests { fn stub_report_builder(report_builder: &mut MockReportBuilder) { report_builder .expect_insert_coverage_sample() - .returning(|_, _, _, _, _, _| { + .returning(|_| { Ok(CoverageSample { ..Default::default() }) }); - report_builder - .expect_insert_branches_data() - .returning(|_, _, _, _, _| { - Ok(BranchesData { - ..Default::default() - }) - }); - report_builder - .expect_insert_method_data() - .returning(|_, _, _, _, _, _, _| { - Ok(MethodData { - ..Default::default() - }) - }); - report_builder - .expect_insert_span_data() - .returning(|_, _, _, _, _, _, _| { - Ok(SpanData { - ..Default::default() - }) - }); - report_builder - .expect_associate_context() - .returning(|_, _, _, _, _| { - Ok(ContextAssoc { - ..Default::default() - }) - }); + report_builder.expect_insert_branches_data().returning(|_| { + Ok(BranchesData { + ..Default::default() + }) + }); + report_builder.expect_insert_method_data().returning(|_| { + Ok(MethodData { + ..Default::default() + }) + }); + report_builder.expect_insert_span_data().returning(|_| { + Ok(SpanData { + ..Default::default() + }) + }); + report_builder.expect_associate_context().returning(|_| { + Ok(ContextAssoc { + ..Default::default() + }) + }); report_builder.expect_insert_context().returning(|_, name| { Ok(Context { name: name.to_string(), diff --git a/src/parsers/pyreport_shim/chunks/utils.rs b/src/parsers/pyreport_shim/chunks/utils.rs index 7a9d335..8545f75 100644 --- a/src/parsers/pyreport_shim/chunks/utils.rs +++ b/src/parsers/pyreport_shim/chunks/utils.rs @@ -66,53 +66,64 @@ fn save_line_session>( let (hits, hit_branches, total_branches) = separate_pyreport_coverage(&line_session.coverage); // Insert the meat of the `LineSession` and get back a `CoverageSample`. - let coverage_sample = ctx.db.report_builder.insert_coverage_sample( - file_id, - ctx.chunk.current_line, - *coverage_type, - hits, - hit_branches, - total_branches, - )?; + let coverage_sample = ctx + .db + .report_builder + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_id, + line_no: ctx.chunk.current_line, + coverage_type: *coverage_type, + hits, + hit_branches, + total_branches, + ..Default::default() + })?; // We already created a `Context` for each session when processing the report // JSON. Get the `Context` ID for the current session and then associate it with // our new `CoverageSample`. let session_id = ctx.report_json_sessions[&line_session.session_id]; - let _ = ctx.db.report_builder.associate_context( - session_id, - Some(&coverage_sample), - None, /* branch_id */ - None, /* method_id */ - None, /* span_id */ - )?; + let _ = ctx + .db + .report_builder + .associate_context(models::ContextAssoc { + context_id: session_id, + sample_id: Some(coverage_sample.id), + ..Default::default() + })?; // Check for and insert any additional branches data that we have. if let Some(Some(missing_branches)) = &line_session.branches { for branch in missing_branches { let (branch_format, branch_serialized) = format_pyreport_branch(branch); - let _ = ctx.db.report_builder.insert_branches_data( - file_id, - coverage_sample.id, - 0, // Chunks file only records missing branches - branch_format, - branch_serialized, - )?; + let _ = ctx + .db + .report_builder + .insert_branches_data(models::BranchesData { + source_file_id: file_id, + sample_id: coverage_sample.id, + hits: 0, // Chunks file only records missing branches + branch_format, + branch: branch_serialized, + ..Default::default() + })?; } } // Check for and insert any additional method data we have. if let Some(Some(complexity)) = &line_session.complexity { let (covered, total) = separate_pyreport_complexity(complexity); - let _ = ctx.db.report_builder.insert_method_data( - file_id, - Some(coverage_sample.id), - Some(ctx.chunk.current_line), - None, /* hit_branches */ - None, /* total_branches */ - covered, - total, - )?; + let _ = ctx + .db + .report_builder + .insert_method_data(models::MethodData { + source_file_id: file_id, + sample_id: Some(coverage_sample.id), + line_no: Some(ctx.chunk.current_line), + hit_complexity_paths: covered, + total_complexity: total, + ..Default::default() + })?; } // Check for and insert any additional span data we have. @@ -127,15 +138,16 @@ fn save_line_session>( PyreportCoverage::HitCount(hits) => *hits as i64, _ => 0, }; - ctx.db.report_builder.insert_span_data( - file_id, - Some(coverage_sample.id), + ctx.db.report_builder.insert_span_data(models::SpanData { + source_file_id: file_id, + sample_id: Some(coverage_sample.id), hits, - Some(ctx.chunk.current_line), - start_col.map(|x| x as i64), - Some(ctx.chunk.current_line), - end_col.map(|x| x as i64), - )?; + start_line: Some(ctx.chunk.current_line), + start_col: start_col.map(|x| x as i64), + end_line: Some(ctx.chunk.current_line), + end_col: end_col.map(|x| x as i64), + ..Default::default() + })?; } } @@ -159,13 +171,14 @@ pub fn save_report_line>( if let Some(datapoint) = datapoints.get(&(line_session.session_id as u32)) { for label in &datapoint.labels { let context_id = ctx.labels_index[label]; - let _ = ctx.db.report_builder.associate_context( - context_id, - Some(&coverage_sample), - None, - None, - None, - )?; + let _ = ctx + .db + .report_builder + .associate_context(models::ContextAssoc { + context_id, + sample_id: Some(coverage_sample.id), + ..Default::default() + })?; } } } @@ -277,45 +290,31 @@ mod tests { hit_branches, total_branches, }; - - // In all cases, we should create a `CoverageSample` - // Clone so we can pass ownership into our mock's closure - let inserted_sample_clone = inserted_coverage_sample.clone(); parse_ctx .db .report_builder .expect_insert_coverage_sample() - .with( - eq(inserted_coverage_sample.source_file_id), - eq(inserted_coverage_sample.line_no), - eq(inserted_coverage_sample.coverage_type), - eq(inserted_coverage_sample.hits), - eq(inserted_coverage_sample.hit_branches), - eq(inserted_coverage_sample.total_branches), - ) - .return_once(move |_, _, _, _, _, _| Ok(inserted_sample_clone)) + .with(eq(models::CoverageSample { + id: uuid::Uuid::nil(), + ..inserted_coverage_sample + })) + .return_once(move |mut sample| { + sample.id = inserted_coverage_sample.id; + Ok(sample) + }) .times(1) .in_sequence(sequence); - // In all cases, we should create this `ContextAssoc` - // Clone so we can pass ownership into our mock's closure - let inserted_sample_clone = inserted_coverage_sample.clone(); parse_ctx .db .report_builder .expect_associate_context() - .withf(move |context, sample, branch, method, span| { - *context == session_context_id - && sample == &Some(&inserted_sample_clone) - && branch.is_none() - && method.is_none() - && span.is_none() - }) - .returning(|_, _, _, _, _| { - Ok(models::ContextAssoc { - ..Default::default() - }) - }) + .with(eq(models::ContextAssoc { + context_id: session_context_id, + sample_id: Some(inserted_coverage_sample.id), + ..Default::default() + })) + .returning(|assoc| Ok(assoc)) .times(1) .in_sequence(sequence); @@ -326,17 +325,17 @@ mod tests { .db .report_builder .expect_insert_branches_data() - .with( - eq(source_file_id), - eq(inserted_coverage_sample.id), - eq(0), - eq(branch_format), - eq(branch_serialized), - ) - .returning(|_, _, _, _, _| { - Ok(models::BranchesData { - ..Default::default() - }) + .with(eq(models::BranchesData { + source_file_id, + sample_id: inserted_coverage_sample.id, + hits: 0, + branch_format, + branch: branch_serialized, + ..Default::default() + })) + .return_once(move |mut branch| { + branch.id = uuid::Uuid::new_v4(); + Ok(branch) }) .times(1) .in_sequence(sequence); @@ -355,19 +354,17 @@ mod tests { .db .report_builder .expect_insert_method_data() - .with( - eq(source_file_id), - eq(Some(inserted_coverage_sample.id)), - eq(Some(inserted_coverage_sample.line_no)), - eq(None), /* hit_branches */ - eq(None), /* hit_branches */ - eq(covered), - eq(total), - ) - .returning(|_, _, _, _, _, _, _| { - Ok(models::MethodData { - ..Default::default() - }) + .with(eq(models::MethodData { + source_file_id, + sample_id: Some(inserted_coverage_sample.id), + line_no: Some(inserted_coverage_sample.line_no), + hit_complexity_paths: covered, + total_complexity: total, + ..Default::default() + })) + .return_once(move |mut method| { + method.id = uuid::Uuid::new_v4(); + Ok(method) }) .times(1) .in_sequence(sequence); @@ -394,19 +391,19 @@ mod tests { .db .report_builder .expect_insert_span_data() - .with( - eq(source_file_id), - eq(Some(inserted_coverage_sample.id)), - eq(hits), - eq(Some(inserted_coverage_sample.line_no)), - eq(start_col.map(|x| x as i64)), - eq(Some(inserted_coverage_sample.line_no)), - eq(end_col.map(|x| x as i64)), - ) - .returning(|_, _, _, _, _, _, _| { - Ok(models::SpanData { - ..Default::default() - }) + .with(eq(models::SpanData { + source_file_id, + sample_id: Some(inserted_coverage_sample.id), + hits, + start_line: Some(inserted_coverage_sample.line_no), + start_col: start_col.map(|x| x as i64), + end_line: Some(inserted_coverage_sample.line_no), + end_col: end_col.map(|x| x as i64), + ..Default::default() + })) + .return_once(move |mut span| { + span.id = uuid::Uuid::new_v4(); + Ok(span) }) .times(1) .in_sequence(sequence); @@ -715,41 +712,27 @@ mod tests { inserted_sample: models::CoverageSample, parse_ctx: &mut ParseCtx>, ) { - let inserted_sample_clone = inserted_sample.clone(); parse_ctx .db .report_builder .expect_associate_context() - .withf(move |context, sample, branch, method, span| { - *context == 50 - && sample == &Some(&inserted_sample_clone) - && branch.is_none() - && method.is_none() - && span.is_none() - }) - .returning(|_, _, _, _, _| { - Ok(models::ContextAssoc { - ..Default::default() - }) - }) + .with(eq(models::ContextAssoc { + context_id: 50, + sample_id: Some(inserted_sample.id), + ..Default::default() + })) + .returning(|assoc| Ok(assoc)) .times(1); - let inserted_sample_clone = inserted_sample.clone(); parse_ctx .db .report_builder .expect_associate_context() - .withf(move |context, sample, branch, method, span| { - *context == 51 - && sample == &Some(&inserted_sample_clone) - && branch.is_none() - && method.is_none() - && span.is_none() - }) - .returning(|_, _, _, _, _| { - Ok(models::ContextAssoc { - ..Default::default() - }) - }) + .with(eq(models::ContextAssoc { + context_id: 51, + sample_id: Some(inserted_sample.id), + ..Default::default() + })) + .returning(|assoc| Ok(assoc)) .times(1); } diff --git a/src/report/mod.rs b/src/report/mod.rs index 3426c22..a797eb9 100644 --- a/src/report/mod.rs +++ b/src/report/mod.rs @@ -5,7 +5,6 @@ pub mod models; mod sqlite_report; pub use sqlite_report::*; -use uuid::Uuid; use crate::error::Result; @@ -38,57 +37,25 @@ pub trait ReportBuilder { fn insert_coverage_sample( &mut self, - source_file_id: i64, - line_no: i64, - coverage_type: models::CoverageType, - hits: Option, - hit_branches: Option, - total_branches: Option, + sample: models::CoverageSample, ) -> Result; fn insert_branches_data( &mut self, - source_file_id: i64, - sample_id: Uuid, - hits: i64, - branch_format: models::BranchFormat, - branch: String, + branch: models::BranchesData, ) -> Result; - fn insert_method_data( - &mut self, - source_file_id: i64, - sample_id: Option, - line_no: Option, - hit_branches: Option, - total_branches: Option, - hit_complexity_paths: Option, - total_complexity: Option, - ) -> Result; + fn insert_method_data(&mut self, method: models::MethodData) -> Result; - fn insert_span_data( - &mut self, - source_file_id: i64, - sample_id: Option, - hits: i64, - start_line: Option, - start_col: Option, - end_line: Option, - end_col: Option, - ) -> Result; + fn insert_span_data(&mut self, span: models::SpanData) -> Result; fn associate_context<'a>( &mut self, - context_id: i64, - sample: Option<&'a models::CoverageSample>, - branches_data: Option<&'a models::BranchesData>, - method_data: Option<&'a models::MethodData>, - span_data: Option<&'a models::SpanData>, + assoc: models::ContextAssoc, ) -> Result; fn insert_upload_details( &mut self, - context_id: i64, upload_details: models::UploadDetails, ) -> Result; diff --git a/src/report/models.rs b/src/report/models.rs index 778a9d7..3787550 100644 --- a/src/report/models.rs +++ b/src/report/models.rs @@ -206,7 +206,7 @@ pub struct CoverageSample { /// If raw coverage data includes information about which specific branches /// stemming from some line were or weren't covered, it can be stored here. -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct BranchesData { pub id: Uuid, pub source_file_id: i64, @@ -228,7 +228,7 @@ pub struct BranchesData { /// If raw coverage data includes additional metrics for methods (cyclomatic /// complexity, aggregated branch coverage) or details like its name or /// signature, they can be stored here. -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct MethodData { pub id: Uuid, pub source_file_id: i64, @@ -270,7 +270,7 @@ pub struct MethodData { /// That information can be stored straightforwardly in this table as-is. /// However, you can also infer that lines 3-7 were all hit 3 times and create /// [`CoverageSample`] records for them. -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct SpanData { pub id: Uuid, pub source_file_id: i64, @@ -297,7 +297,7 @@ pub struct SpanData { } /// Ties a [`Context`] to specific measurement data. -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct ContextAssoc { pub context_id: i64, pub sample_id: Option, @@ -308,7 +308,7 @@ pub struct ContextAssoc { /// Context that can be associated with measurements to allow querying/filtering /// based on test cases, platforms, or other dimensions. -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct Context { /// Should be a hash of the name pub id: i64, @@ -319,7 +319,7 @@ pub struct Context { pub name: String, } -#[derive(PartialEq, Debug, Default)] +#[derive(PartialEq, Debug, Default, Clone)] pub struct UploadDetails { pub context_id: i64, pub timestamp: Option, diff --git a/src/report/sqlite_report.rs b/src/report/sqlite_report.rs index c5a4272..17fa69d 100644 --- a/src/report/sqlite_report.rs +++ b/src/report/sqlite_report.rs @@ -278,182 +278,95 @@ impl ReportBuilder for SqliteReportBuilder { fn insert_coverage_sample( &mut self, - source_file_id: i64, - line_no: i64, - coverage_type: models::CoverageType, - hits: Option, - hit_branches: Option, - total_branches: Option, + mut sample: models::CoverageSample, ) -> Result { - let mut stmt = self.conn.prepare("INSERT INTO coverage_sample (id, source_file_id, line_no, coverage_type, hits, hit_branches, total_branches) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7) RETURNING id, source_file_id, line_no, coverage_type, hits, hit_branches, total_branches")?; - Ok(stmt.query_row( - ( - Uuid::new_v4(), - source_file_id, - line_no, - coverage_type, - hits, - hit_branches, - total_branches, - ), - |row| { - Ok(models::CoverageSample { - id: row.get(0)?, - source_file_id: row.get(1)?, - line_no: row.get(2)?, - coverage_type: row.get(3)?, - hits: row.get(4)?, - hit_branches: row.get(5)?, - total_branches: row.get(6)?, - }) - }, - )?) + let mut stmt = self.conn.prepare("INSERT INTO coverage_sample (id, source_file_id, line_no, coverage_type, hits, hit_branches, total_branches) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)")?; + sample.id = Uuid::new_v4(); + let _ = stmt.execute(( + sample.id, + sample.source_file_id, + sample.line_no, + sample.coverage_type, + sample.hits, + sample.hit_branches, + sample.total_branches, + ))?; + + Ok(sample) } fn insert_branches_data( &mut self, - source_file_id: i64, - sample_id: Uuid, - hits: i64, - branch_format: models::BranchFormat, - branch: String, + mut branch: models::BranchesData, ) -> Result { - let mut stmt = self.conn.prepare("INSERT INTO branches_data (id, source_file_id, sample_id, hits, branch_format, branch) VALUES (?1, ?2, ?3, ?4, ?5, ?6) RETURNING id, source_file_id, sample_id, hits, branch_format, branch")?; + let mut stmt = self.conn.prepare("INSERT INTO branches_data (id, source_file_id, sample_id, hits, branch_format, branch) VALUES (?1, ?2, ?3, ?4, ?5, ?6)")?; - Ok(stmt.query_row( - ( - Uuid::new_v4(), - source_file_id, - sample_id, - hits, - branch_format, - branch, - ), - |row| { - Ok(models::BranchesData { - id: row.get(0)?, - source_file_id: row.get(1)?, - sample_id: row.get(2)?, - hits: row.get(3)?, - branch_format: row.get(4)?, - branch: row.get(5)?, - }) - }, - )?) + branch.id = Uuid::new_v4(); + let _ = stmt.execute(( + branch.id, + branch.source_file_id, + branch.sample_id, + branch.hits, + branch.branch_format, + &branch.branch, + ))?; + Ok(branch) } - fn insert_method_data( - &mut self, - source_file_id: i64, - sample_id: Option, - line_no: Option, - hit_branches: Option, - total_branches: Option, - hit_complexity_paths: Option, - total_complexity: Option, - ) -> Result { - let mut stmt = self.conn.prepare("INSERT INTO method_data (id, source_file_id, sample_id, line_no, hit_branches, total_branches, hit_complexity_paths, total_complexity) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8) RETURNING id, source_file_id, sample_id, line_no, hit_branches, total_branches, hit_complexity_paths, total_complexity")?; + fn insert_method_data(&mut self, mut method: models::MethodData) -> Result { + let mut stmt = self.conn.prepare("INSERT INTO method_data (id, source_file_id, sample_id, line_no, hit_branches, total_branches, hit_complexity_paths, total_complexity) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)")?; + method.id = Uuid::new_v4(); - Ok(stmt.query_row( - ( - Uuid::new_v4(), - source_file_id, - sample_id, - line_no, - hit_branches, - total_branches, - hit_complexity_paths, - total_complexity, - ), - |row| { - Ok(models::MethodData { - id: row.get(0)?, - source_file_id: row.get(1)?, - sample_id: row.get(2)?, - line_no: row.get(3)?, - hit_branches: row.get(4)?, - total_branches: row.get(5)?, - hit_complexity_paths: row.get(6)?, - total_complexity: row.get(7)?, - }) - }, - )?) + let _ = stmt.execute(( + method.id, + method.source_file_id, + method.sample_id, + method.line_no, + method.hit_branches, + method.total_branches, + method.hit_complexity_paths, + method.total_complexity, + ))?; + Ok(method) } - fn insert_span_data( - &mut self, - source_file_id: i64, - sample_id: Option, - hits: i64, - start_line: Option, - start_col: Option, - end_line: Option, - end_col: Option, - ) -> Result { - let mut stmt = self.conn.prepare("INSERT INTO span_data (id, source_file_id, sample_id, hits, start_line, start_col, end_line, end_col) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8) RETURNING id, source_file_id, sample_id, hits, start_line, start_col, end_line, end_col")?; + fn insert_span_data(&mut self, mut span: models::SpanData) -> Result { + let mut stmt = self.conn.prepare("INSERT INTO span_data (id, source_file_id, sample_id, hits, start_line, start_col, end_line, end_col) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)")?; + span.id = Uuid::new_v4(); - Ok(stmt.query_row( - ( - Uuid::new_v4(), - source_file_id, - sample_id, - hits, - start_line, - start_col, - end_line, - end_col, - ), - |row| { - Ok(models::SpanData { - id: row.get(0)?, - source_file_id: row.get(1)?, - sample_id: row.get(2)?, - hits: row.get(3)?, - start_line: row.get(4)?, - start_col: row.get(5)?, - end_line: row.get(6)?, - end_col: row.get(7)?, - }) - }, - )?) + let _ = stmt.execute(( + span.id, + span.source_file_id, + span.sample_id, + span.hits, + span.start_line, + span.start_col, + span.end_line, + span.end_col, + ))?; + Ok(span) } fn associate_context<'a>( &mut self, - context_id: i64, - sample: Option<&'a models::CoverageSample>, - branches_data: Option<&'a models::BranchesData>, - method_data: Option<&'a models::MethodData>, - span_data: Option<&'a models::SpanData>, + assoc: models::ContextAssoc, ) -> Result { - let mut stmt = self.conn.prepare("INSERT INTO context_assoc (context_id, sample_id, branch_id, method_id, span_id) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING context_id, sample_id, branch_id, method_id, span_id")?; + let mut stmt = self.conn.prepare("INSERT INTO context_assoc (context_id, sample_id, branch_id, method_id, span_id) VALUES (?1, ?2, ?3, ?4, ?5)")?; - Ok(stmt.query_row( - ( - context_id, - sample.map(|s| s.id), - branches_data.map(|b| b.id), - method_data.map(|m| m.id), - span_data.map(|s| s.id), - ), - |row| { - Ok(models::ContextAssoc { - context_id: row.get(0)?, - sample_id: row.get(1)?, - branch_id: row.get(2)?, - method_id: row.get(3)?, - span_id: row.get(4)?, - }) - }, - )?) + let _ = stmt.execute(( + assoc.context_id, + assoc.sample_id, + assoc.branch_id, + assoc.method_id, + assoc.span_id, + ))?; + Ok(assoc) } fn insert_upload_details( &mut self, - context_id: i64, - mut upload_details: models::UploadDetails, + upload_details: models::UploadDetails, ) -> Result { - upload_details.context_id = context_id; let mut stmt = self.conn.prepare("INSERT INTO upload_details (context_id, timestamp, raw_upload_url, flags, provider, build, name, job_name, ci_run_url, state, env, session_type, session_extras) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13)")?; let _ = stmt.execute(( &upload_details.context_id, @@ -574,43 +487,38 @@ mod tests { .insert_context(models::ContextType::Upload, "codecov-rs CI") .unwrap(); let line_1 = left_report_builder - .insert_coverage_sample( - file_1.id, - 1, - models::CoverageType::Line, - Some(1), - None, - None, - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_1.id, + line_no: 1, + coverage_type: models::CoverageType::Line, + ..Default::default() + }) .unwrap(); let line_2 = left_report_builder - .insert_coverage_sample( - file_2.id, - 1, - models::CoverageType::Branch, - None, - Some(1), - Some(2), - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_2.id, + line_no: 1, + coverage_type: models::CoverageType::Branch, + hit_branches: Some(1), + total_branches: Some(2), + ..Default::default() + }) .unwrap(); let line_3 = left_report_builder - .insert_coverage_sample( - file_2.id, - 2, - models::CoverageType::Method, - Some(2), - None, - None, - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_2.id, + line_no: 2, + coverage_type: models::CoverageType::Method, + hits: Some(2), + ..Default::default() + }) .unwrap(); for line in [&line_1, &line_2, &line_3] { - let _ = left_report_builder.associate_context( - context_1.id, - Some(line), - None, - None, - None, - ); + let _ = left_report_builder.associate_context(models::ContextAssoc { + context_id: context_1.id, + sample_id: Some(line.id), + ..Default::default() + }); } let mut right_report_builder = SqliteReportBuilder::new(db_file_right).unwrap(); @@ -624,59 +532,55 @@ mod tests { .insert_context(models::ContextType::Upload, "codecov-rs CI 2") .unwrap(); let line_4 = right_report_builder - .insert_coverage_sample( - file_2.id, - 3, - models::CoverageType::Line, - Some(1), - None, - None, - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_2.id, + line_no: 3, + coverage_type: models::CoverageType::Line, + hits: Some(1), + ..Default::default() + }) .unwrap(); let line_5 = right_report_builder - .insert_coverage_sample( - file_3.id, - 1, - models::CoverageType::Branch, - None, - Some(1), - Some(2), - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_3.id, + line_no: 1, + coverage_type: models::CoverageType::Branch, + hit_branches: Some(1), + total_branches: Some(2), + ..Default::default() + }) .unwrap(); - let _ = right_report_builder.insert_branches_data( - file_2.id, - line_5.id, - 0, - models::BranchFormat::Condition, - "1".to_string(), - ); + let _ = right_report_builder.insert_branches_data(models::BranchesData { + source_file_id: file_2.id, + sample_id: line_5.id, + hits: 0, + branch_format: models::BranchFormat::Condition, + branch: "1".to_string(), + ..Default::default() + }); let line_6 = right_report_builder - .insert_coverage_sample( - file_2.id, - 2, - models::CoverageType::Method, - Some(2), - None, - None, - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file_2.id, + line_no: 2, + coverage_type: models::CoverageType::Method, + hits: Some(2), + ..Default::default() + }) .unwrap(); - let _ = right_report_builder.insert_method_data( - file_2.id, - Some(line_6.id), - Some(2), - None, - None, - Some(1), - Some(2), - ); + let _ = right_report_builder.insert_method_data(models::MethodData { + source_file_id: file_2.id, + sample_id: Some(line_6.id), + line_no: Some(2), + hit_complexity_paths: Some(1), + total_complexity: Some(2), + ..Default::default() + }); for line in [&line_4, &line_5, &line_6] { - let _ = right_report_builder.associate_context( - context_2.id, - Some(line), - None, - None, - None, - ); + let _ = right_report_builder.associate_context(models::ContextAssoc { + context_id: context_2.id, + sample_id: Some(line.id), + ..Default::default() + }); } let mut left = left_report_builder.build(); @@ -790,15 +694,9 @@ mod tests { total_branches: Some(4), }; let actual_sample = report_builder - .insert_coverage_sample( - expected_sample.source_file_id, - expected_sample.line_no, - expected_sample.coverage_type, - expected_sample.hits, - expected_sample.hit_branches, - expected_sample.total_branches, - ) + .insert_coverage_sample(expected_sample.clone()) .unwrap(); + assert_ne!(expected_sample.id, actual_sample.id); expected_sample.id = actual_sample.id.clone(); assert_eq!(actual_sample, expected_sample); } @@ -814,14 +712,14 @@ mod tests { .unwrap(); let coverage_sample = report_builder - .insert_coverage_sample( - file.id, - 1, // line_no - models::CoverageType::Branch, - None, // hits - Some(2), // hit_branches - Some(4), // total_branches - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file.id, + line_no: 1, + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), + total_branches: Some(4), + ..Default::default() + }) .unwrap(); let mut expected_branch = models::BranchesData { @@ -833,14 +731,9 @@ mod tests { branch: "0:jump".to_string(), }; let actual_branch = report_builder - .insert_branches_data( - expected_branch.source_file_id, - expected_branch.sample_id, - expected_branch.hits, - expected_branch.branch_format, - expected_branch.branch.clone(), - ) + .insert_branches_data(expected_branch.clone()) .unwrap(); + assert_ne!(expected_branch.id, actual_branch.id); expected_branch.id = actual_branch.id; assert_eq!(actual_branch, expected_branch); } @@ -856,14 +749,14 @@ mod tests { .unwrap(); let coverage_sample = report_builder - .insert_coverage_sample( - file.id, - 1, // line_no - models::CoverageType::Branch, - None, // hits - Some(2), // hit_branches - Some(4), // total_branches - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file.id, + line_no: 1, // line_no + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), // hit_branches + total_branches: Some(4), // total_branches + ..Default::default() + }) .unwrap(); let mut expected_method = models::MethodData { @@ -878,15 +771,7 @@ mod tests { }; let actual_method = report_builder - .insert_method_data( - expected_method.source_file_id, - expected_method.sample_id, - expected_method.line_no, - expected_method.hit_branches, - expected_method.total_branches, - expected_method.hit_complexity_paths, - expected_method.total_complexity, - ) + .insert_method_data(expected_method.clone()) .unwrap(); expected_method.id = actual_method.id; assert_eq!(actual_method, expected_method); @@ -903,14 +788,14 @@ mod tests { .unwrap(); let coverage_sample = report_builder - .insert_coverage_sample( - file.id, - 1, // line_no - models::CoverageType::Branch, - None, // hits - Some(2), // hit_branches - Some(4), // total_branches - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file.id, + line_no: 1, // line_no + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), // hit_branches + total_branches: Some(4), // total_branches + ..Default::default() + }) .unwrap(); let mut expected_span = models::SpanData { @@ -924,15 +809,7 @@ mod tests { end_col: Some(60), }; let actual_span = report_builder - .insert_span_data( - expected_span.source_file_id, - expected_span.sample_id, - expected_span.hits, - expected_span.start_line, - expected_span.start_col, - expected_span.end_line, - expected_span.end_col, - ) + .insert_span_data(expected_span.clone()) .unwrap(); expected_span.id = actual_span.id; assert_eq!(actual_span, expected_span); @@ -949,48 +826,51 @@ mod tests { .unwrap(); let coverage_sample = report_builder - .insert_coverage_sample( - file.id, - 1, // line_no - models::CoverageType::Branch, - None, // hits - Some(2), // hit_branches - Some(4), // total_branches - ) + .insert_coverage_sample(models::CoverageSample { + source_file_id: file.id, + line_no: 1, // line_no + coverage_type: models::CoverageType::Branch, + hit_branches: Some(2), // hit_branches + total_branches: Some(4), // total_branches + ..Default::default() + }) .unwrap(); let branch = report_builder - .insert_branches_data( - file.id, - coverage_sample.id, - 0, // hits - models::BranchFormat::Condition, - "0:jump".to_string(), - ) + .insert_branches_data(models::BranchesData { + source_file_id: file.id, + sample_id: coverage_sample.id, + hits: 0, // hits + branch_format: models::BranchFormat::Condition, + branch: "0:jump".to_string(), + ..Default::default() + }) .unwrap(); let method = report_builder - .insert_method_data( - file.id, - Some(coverage_sample.id), - Some(1), // line_no - Some(1), // hit_branches - Some(2), // total_branches - Some(1), // hit_complexity_paths - Some(2), // total_complexity_paths - ) + .insert_method_data(models::MethodData { + source_file_id: file.id, + sample_id: Some(coverage_sample.id), + line_no: Some(1), + hit_branches: Some(1), + total_branches: Some(2), + hit_complexity_paths: Some(1), + total_complexity: Some(2), + ..Default::default() + }) .unwrap(); let span = report_builder - .insert_span_data( - file.id, - Some(coverage_sample.id), - 1, // hits - Some(1), // start_line - Some(0), // start_col - Some(30), // end_line - Some(60), // end_col - ) + .insert_span_data(models::SpanData { + source_file_id: file.id, + sample_id: Some(coverage_sample.id), + hits: 1, // hits + start_line: Some(1), // start_line + start_col: Some(0), // start_col + end_line: Some(30), // end_line + end_col: Some(60), // end_col + ..Default::default() + }) .unwrap(); let context = report_builder @@ -1005,13 +885,13 @@ mod tests { span_id: Some(span.id), }; let actual_assoc = report_builder - .associate_context( - context.id, - Some(&coverage_sample), - Some(&branch), - Some(&method), - Some(&span), - ) + .associate_context(models::ContextAssoc { + context_id: context.id, + sample_id: Some(coverage_sample.id), + branch_id: Some(branch.id), + method_id: Some(method.id), + span_id: Some(span.id), + }) .unwrap(); assert_eq!(actual_assoc, expected_assoc); } @@ -1041,7 +921,7 @@ mod tests { session_extras: Some(json!({})), }; let inserted_details = report_builder - .insert_upload_details(upload.id, inserted_details) + .insert_upload_details(inserted_details) .unwrap(); let other_upload = report_builder