docker_wrapper/template/redis/
insight.rs1#![allow(clippy::doc_markdown)]
4#![allow(clippy::must_use_candidate)]
5#![allow(clippy::return_self_not_must_use)]
6#![allow(clippy::needless_borrows_for_generic_args)]
7#![allow(clippy::unnecessary_get_then_check)]
8
9use super::common::{DEFAULT_REDIS_INSIGHT_PORT, REDIS_INSIGHT_IMAGE, REDIS_INSIGHT_TAG};
10use crate::template::{Template, TemplateConfig};
11use async_trait::async_trait;
12use std::collections::HashMap;
13
14pub struct RedisInsightTemplate {
16 config: TemplateConfig,
17}
18
19impl RedisInsightTemplate {
20 pub fn new(name: impl Into<String>) -> Self {
22 let name = name.into();
23 let env = HashMap::new();
24
25 let config = TemplateConfig {
26 name: name.clone(),
27 image: REDIS_INSIGHT_IMAGE.to_string(),
28 tag: REDIS_INSIGHT_TAG.to_string(),
29 ports: vec![(DEFAULT_REDIS_INSIGHT_PORT, 5540)],
30 env,
31 volumes: Vec::new(),
32 network: None,
33 health_check: None, auto_remove: false,
35 memory_limit: None,
36 cpu_limit: None,
37 platform: None,
38 };
39
40 Self { config }
41 }
42
43 pub fn port(mut self, port: u16) -> Self {
45 self.config.ports = vec![(port, 5540)];
46 self
47 }
48
49 pub fn network(mut self, network: impl Into<String>) -> Self {
51 self.config.network = Some(network.into());
52 self
53 }
54
55 pub fn auto_remove(mut self) -> Self {
57 self.config.auto_remove = true;
58 self
59 }
60
61 pub fn memory_limit(mut self, limit: impl Into<String>) -> Self {
63 self.config.memory_limit = Some(limit.into());
64 self
65 }
66
67 pub fn custom_image(mut self, image: impl Into<String>, tag: impl Into<String>) -> Self {
69 self.config.image = image.into();
70 self.config.tag = tag.into();
71 self
72 }
73
74 pub fn platform(mut self, platform: impl Into<String>) -> Self {
76 self.config.platform = Some(platform.into());
77 self
78 }
79}
80
81#[async_trait]
82impl Template for RedisInsightTemplate {
83 fn name(&self) -> &str {
84 &self.config.name
85 }
86
87 fn config(&self) -> &TemplateConfig {
88 &self.config
89 }
90
91 fn config_mut(&mut self) -> &mut TemplateConfig {
92 &mut self.config
93 }
94}
95
96#[cfg(test)]
97mod tests {
98 use super::*;
99
100 #[test]
101 fn test_redisinsight_template_basic() {
102 let template = RedisInsightTemplate::new("test-insight");
103 assert_eq!(template.name(), "test-insight");
104 assert_eq!(template.config().image, REDIS_INSIGHT_IMAGE);
105 assert_eq!(template.config().tag, REDIS_INSIGHT_TAG);
106 assert_eq!(
107 template.config().ports,
108 vec![(DEFAULT_REDIS_INSIGHT_PORT, 5540)]
109 );
110 }
111
112 #[test]
113 fn test_redisinsight_template_custom_port() {
114 let template = RedisInsightTemplate::new("test-insight").port(8080);
115 assert_eq!(template.config().ports, vec![(8080, 5540)]);
116 }
117
118 #[test]
119 fn test_redisinsight_template_with_network() {
120 let template = RedisInsightTemplate::new("test-insight").network("redis-network");
121 assert_eq!(template.config().network, Some("redis-network".to_string()));
122 }
123
124 #[test]
125 fn test_redisinsight_template_auto_remove() {
126 let template = RedisInsightTemplate::new("test-insight").auto_remove();
127 assert!(template.config().auto_remove);
128 }
129}