Skip to content

Commit ccd6fd2

Browse files
committed
test: add tests to improve test coverage
1 parent 1859265 commit ccd6fd2

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

postgresql_archive/src/repository/github/repository.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,26 @@ mod tests {
368368
assert_eq!("GitHub", github.name());
369369
}
370370

371+
#[test]
372+
fn test_get_version_from_tag_name() -> Result<()> {
373+
let versions = vec!["16.3.0", "v16.3.0"];
374+
for version in versions {
375+
let version = GitHub::get_version_from_tag_name(version)?;
376+
assert_eq!(Version::new(16, 3, 0), version);
377+
}
378+
379+
Ok(())
380+
}
381+
382+
#[test]
383+
fn test_get_version_from_tag_name_error() {
384+
let error = GitHub::get_version_from_tag_name("foo").unwrap_err();
385+
assert_eq!(
386+
"empty string, expected a semver version".to_string(),
387+
error.to_string()
388+
);
389+
}
390+
371391
//
372392
// get_version tests
373393
//

postgresql_archive/src/version.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ impl ExactVersion for VersionReq {
1616
if self.comparators.len() != 1 {
1717
return None;
1818
}
19-
20-
if let Some(comparator) = self.comparators.first() {
21-
if comparator.op != semver::Op::Exact {
22-
return None;
23-
}
24-
let minor = comparator.minor?;
25-
let patch = comparator.patch?;
26-
27-
let version = Version::new(comparator.major, minor, patch);
28-
return Some(version);
19+
let comparator = self.comparators.first()?;
20+
if comparator.op != semver::Op::Exact {
21+
return None;
2922
}
30-
31-
None
23+
let minor = comparator.minor?;
24+
let patch = comparator.patch?;
25+
let version = Version::new(comparator.major, minor, patch);
26+
Some(version)
3227
}
3328
}
3429

@@ -99,6 +94,13 @@ mod tests {
9994
Ok(())
10095
}
10196

97+
#[test]
98+
fn test_exact_version_range() -> Result<()> {
99+
let version_req = VersionReq::parse(">= 16, < 17")?;
100+
assert_eq!(None, version_req.exact_version());
101+
Ok(())
102+
}
103+
102104
#[test]
103105
fn test_exact_version_req_not_equal() -> Result<()> {
104106
let version = Version::new(1, 2, 3);

0 commit comments

Comments
 (0)