Skip to content

Commit d986d4d

Browse files
committed
add test cases to ensure duplicate inserts for source_file/context/context_assoc fail
1 parent 338385b commit d986d4d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/report/sqlite/report_builder.rs

+54
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,22 @@ mod tests {
384384
.insert_file(expected_file.path.clone())
385385
.unwrap();
386386
assert_eq!(actual_file, expected_file);
387+
388+
let duplicate_result = report_builder.insert_file(expected_file.path.clone());
389+
match duplicate_result {
390+
Err(CodecovError::SqliteError(rusqlite::Error::SqliteFailure(
391+
rusqlite::ffi::Error {
392+
code: rusqlite::ffi::ErrorCode::ConstraintViolation,
393+
extended_code: 1555,
394+
},
395+
Some(s),
396+
))) => {
397+
assert_eq!(s, String::from("UNIQUE constraint failed: source_file.id"));
398+
}
399+
_ => {
400+
assert!(false);
401+
}
402+
}
387403
}
388404

389405
#[test]
@@ -401,6 +417,23 @@ mod tests {
401417
.insert_context(expected_context.context_type, &expected_context.name)
402418
.unwrap();
403419
assert_eq!(actual_context, expected_context);
420+
421+
let duplicate_result =
422+
report_builder.insert_context(expected_context.context_type, &expected_context.name);
423+
match duplicate_result {
424+
Err(CodecovError::SqliteError(rusqlite::Error::SqliteFailure(
425+
rusqlite::ffi::Error {
426+
code: rusqlite::ffi::ErrorCode::ConstraintViolation,
427+
extended_code: 1555,
428+
},
429+
Some(s),
430+
))) => {
431+
assert_eq!(s, String::from("UNIQUE constraint failed: context.id"));
432+
}
433+
_ => {
434+
assert!(false);
435+
}
436+
}
404437
}
405438

406439
#[test]
@@ -623,6 +656,27 @@ mod tests {
623656
})
624657
.unwrap();
625658
assert_eq!(actual_assoc, expected_assoc);
659+
660+
let duplicate_result = report_builder.associate_context(expected_assoc.clone());
661+
match duplicate_result {
662+
Err(CodecovError::SqliteError(rusqlite::Error::SqliteFailure(
663+
rusqlite::ffi::Error {
664+
code: rusqlite::ffi::ErrorCode::ConstraintViolation,
665+
extended_code: 1555,
666+
},
667+
Some(s),
668+
))) => {
669+
assert_eq!(
670+
s,
671+
String::from(
672+
"UNIQUE constraint failed: context_assoc.context_id, context_assoc.sample_id"
673+
)
674+
);
675+
}
676+
_ => {
677+
assert!(false);
678+
}
679+
}
626680
}
627681

628682
#[test]

0 commit comments

Comments
 (0)