Compare commits
2 Commits
0a844c42ee
...
cb78c58de1
Author | SHA1 | Date | |
---|---|---|---|
|
cb78c58de1 | ||
|
0edfd45d38 |
19
src/repo.rs
19
src/repo.rs
@ -102,7 +102,6 @@ pub fn split_repo_without_tag(repo: &str) -> Result<Repo, Error> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::repo;
|
|
||||||
use crate::repo::{Error, Repo};
|
use crate::repo::{Error, Repo};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -128,23 +127,23 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_match_yaml_image() {
|
fn test_match_yaml_image() {
|
||||||
use crate::repo::match_yaml_image as test_fn;
|
use crate::repo::match_yaml_image as test_fn;
|
||||||
assert_eq!(test_fn(""), None);
|
assert_eq!(test_fn(""), Err(Error::NoTagFound));
|
||||||
assert_eq!(test_fn("version: '2'"), None);
|
assert_eq!(test_fn("version: '2'"), Err(Error::NoTagFound));
|
||||||
assert_eq!(test_fn("image: "), None);
|
assert_eq!(test_fn("image: "), Err(Error::NoTagFound));
|
||||||
assert_eq!(test_fn(" image: "), None);
|
assert_eq!(test_fn(" image: "), Err(Error::NoTagFound));
|
||||||
assert_eq!(test_fn(" image: nginx"), Some((" image: ", "nginx")));
|
assert_eq!(test_fn(" image: nginx"), Ok((" image: ", "nginx")));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_fn(" image: library/nginx"),
|
test_fn(" image: library/nginx"),
|
||||||
Some((" image: ", "library/nginx"))
|
Ok((" image: ", "library/nginx"))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_fn(" image: ghcr.io/library/nginx"),
|
test_fn(" image: ghcr.io/library/nginx"),
|
||||||
Some((" image: ", "ghcr.io/library/nginx"))
|
Ok((" image: ", "ghcr.io/library/nginx"))
|
||||||
);
|
);
|
||||||
assert_eq!(test_fn("# image: nginx"), None);
|
assert_eq!(test_fn("# image: nginx"), Err(Error::NoTagFound));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
test_fn(" image: nginx #comment"),
|
test_fn(" image: nginx #comment"),
|
||||||
Some((" image: ", "nginx"))
|
Ok((" image: ", "nginx"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
src/tags.rs
11
src/tags.rs
@ -13,7 +13,7 @@ struct ImageDetails {
|
|||||||
|
|
||||||
impl fmt::Display for ImageDetails {
|
impl fmt::Display for ImageDetails {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "[{}, {}MB]", self.architecture, self.size / 1024 / 1024)
|
write!(f, "{}|{}MB", self.architecture, self.size / 1024 / 1024)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,16 +122,19 @@ impl fmt::Display for Images {
|
|||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
//architecture infos
|
//architecture infos
|
||||||
let mut arch = String::new();
|
let mut arch = String::new();
|
||||||
for image in &self.images {
|
for image in self.images.iter().take(1) {
|
||||||
arch.push_str(&format!("{}", image));
|
arch.push_str(&format!("{}", image));
|
||||||
}
|
}
|
||||||
|
for image in self.images.iter().skip(1) {
|
||||||
|
arch.push_str(&format!(", {}", image));
|
||||||
|
}
|
||||||
|
|
||||||
let now = chrono::Utc::now();
|
let now = chrono::Utc::now();
|
||||||
let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap();
|
let rfc3339 = DateTime::parse_from_rfc3339(&self.last_updated).unwrap();
|
||||||
let dif = now - rfc3339.with_timezone(&chrono::Utc);
|
let dif = now - rfc3339.with_timezone(&chrono::Utc);
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{} vor {} {}",
|
"{} vor {} [{}]",
|
||||||
self.tag_name,
|
self.tag_name,
|
||||||
format_time_nice(dif),
|
format_time_nice(dif),
|
||||||
arch
|
arch
|
||||||
@ -164,7 +167,7 @@ fn format_time_nice(time: chrono::Duration) -> String {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tags::{Error, Tags};
|
use crate::tags::Tags;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_repo() {
|
fn test_check_repo() {
|
||||||
assert_eq!(Tags::check_repo("nginx").unwrap(), "library/nginx");
|
assert_eq!(Tags::check_repo("nginx").unwrap(), "library/nginx");
|
||||||
|
Loading…
Reference in New Issue
Block a user