use anyhow::Result;
use std::path::PathBuf;
use tempfile::TempDir;
use crate::notifier::Notifier;
pub trait Source {
fn name(&self) -> &str;
fn get_image_tarball(
&self,
image_name: &str,
notifier: &Notifier,
) -> Result<(PathBuf, Option<TempDir>)>;
fn branch_name(&self, image_name: &str, os_arch: &str, image_digest: &str) -> String;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::sources::{DockerSource, TarSource};
#[test]
fn test_polymorphic_branch_naming() {
let docker_source = DockerSource::new().unwrap();
assert_eq!(
docker_source.branch_name(
"hello-world:latest",
"linux-amd64",
"sha256:1234567890abcdef"
),
"hello-world#latest#linux-amd64#1234567890ab"
);
assert_eq!(
docker_source.branch_name("nginx/nginx:1.21", "linux-arm64", "sha256:9876543210fedcba"),
"nginx-nginx#1.21#linux-arm64#9876543210fe"
);
let tar_source = TarSource::new().unwrap();
assert_eq!(
tar_source.branch_name(
"/path/to/my-image.tar",
"linux-amd64",
"sha256:1234567890abcdef"
),
"my-image#linux-amd64#1234567890ab"
);
assert_eq!(
tar_source.branch_name(
"ubuntu 20.04.tar",
"windows-amd64",
"sha256:abcdef123456789"
),
"ubuntu-20-04#windows-amd64#abcdef123456"
);
}
}