testcontainers_magento_data/core/image/
name.rs

1use crate::core::{ImageRepository, DEFAULT_IMAGE_REPOSITORY};
2
3#[derive(Debug, PartialEq)]
4pub struct ImageName {
5    name: String,
6    path: String,
7}
8
9impl ImageName {
10    pub fn new(name: impl Into<String>) -> Self {
11        let name = name.into();
12        let path = DEFAULT_IMAGE_REPOSITORY.image_path(&name);
13
14        Self { name, path }
15    }
16
17    pub fn with_repository(self, repository: impl ImageRepository) -> Self {
18        let path = repository.image_path(&self.name);
19        Self { path, ..self }
20    }
21}
22
23impl AsRef<str> for ImageName {
24    fn as_ref(&self) -> &str {
25        &self.path
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn creates_name_from_default_repository() {
35        ImageName::new("mysql");
36
37        assert_eq!(
38            ImageName::new("mysql").as_ref(),
39            "ghcr.io/ecomdev/testcontainer-magento-data/mysql"
40        );
41    }
42
43    #[test]
44    fn allows_to_override_repository_of_the_image() {
45        assert_eq!(
46            ImageName::new("mariadb")
47                .with_repository("docker.io/library")
48                .as_ref(),
49            "docker.io/library/mariadb"
50        );
51    }
52}