/home/runner/work/lyquor/lyquor/testing/test/src/oci.rs
Line | Count | Source |
1 | | use testcontainers::{ContainerAsync, Image, TestcontainersError, core::WaitFor, runners::AsyncRunner}; |
2 | | |
3 | | /// Container port exposed by the local OCI registry used in tests. |
4 | | pub const LYQUOR_REGISTRY_TEST_PORT: u16 = 5000; |
5 | | const TEST_REGISTRY_IMAGE: &str = "registry"; |
6 | | const TEST_REGISTRY_TAG: &str = "3.0.0"; |
7 | | |
8 | | /// Running test OCI registry container. |
9 | | #[derive(Debug)] |
10 | | pub struct TestRegistry { |
11 | | _container: ContainerAsync<TestRegistryImage>, |
12 | | addr: String, |
13 | | } |
14 | | |
15 | | impl TestRegistry { |
16 | | /// Start a disposable OCI registry container. |
17 | 8 | pub async fn start() -> Result<Self, TestcontainersError> { |
18 | 8 | let container = TestRegistryImage.start().await?0 ; |
19 | 8 | let host = container.get_host().await?0 ; |
20 | 8 | let port = container.get_host_port_ipv4(LYQUOR_REGISTRY_TEST_PORT).await?0 ; |
21 | 8 | let addr = format!("{host}:{port}"); |
22 | 8 | Ok(Self { |
23 | 8 | _container: container, |
24 | 8 | addr, |
25 | 8 | }) |
26 | 8 | } |
27 | | |
28 | | /// Return the host address for clients to push and pull images. |
29 | 8 | pub fn addr(&self) -> &str { |
30 | 8 | &self.addr |
31 | 8 | } |
32 | | } |
33 | | |
34 | | #[derive(Debug, Default)] |
35 | | struct TestRegistryImage; |
36 | | |
37 | | impl Image for TestRegistryImage { |
38 | 13 | fn name(&self) -> &str { |
39 | 13 | TEST_REGISTRY_IMAGE |
40 | 13 | } |
41 | | |
42 | 13 | fn tag(&self) -> &str { |
43 | 13 | TEST_REGISTRY_TAG |
44 | 13 | } |
45 | | |
46 | 8 | fn ready_conditions(&self) -> Vec<WaitFor> { |
47 | 8 | vec![WaitFor::message_on_stderr("listening on")] |
48 | 8 | } |
49 | | } |