docker_wrapper/compose/
build.rs1use super::{execute_compose_command, ComposeCommand, ComposeConfig, ComposeOutput};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone, Default)]
9#[allow(dead_code)] #[allow(clippy::struct_excessive_bools)] pub struct ComposeBuildCommand {
12 config: ComposeConfig,
13 services: Vec<String>,
14 no_cache: bool,
15 pull: bool,
16 quiet: bool,
17 build_arg: Vec<(String, String)>,
18 parallel: bool,
19}
20
21impl ComposeBuildCommand {
22 #[must_use]
24 pub fn new() -> Self {
25 Self::default()
26 }
27
28 pub async fn run(&self) -> Result<ComposeOutput> {
34 self.execute().await
35 }
36}
37
38#[async_trait]
39impl ComposeCommand for ComposeBuildCommand {
40 type Output = ComposeOutput;
41
42 fn subcommand(&self) -> &'static str {
43 "build"
44 }
45
46 fn build_args(&self) -> Vec<String> {
47 Vec::new()
48 }
49
50 async fn execute(&self) -> Result<Self::Output> {
51 execute_compose_command(&self.config, self.subcommand(), self.build_args()).await
52 }
53
54 fn config(&self) -> &ComposeConfig {
55 &self.config
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_compose_build_basic() {
65 let cmd = ComposeBuildCommand::new();
66 assert_eq!(cmd.subcommand(), "build");
67 assert_eq!(cmd.build_args(), Vec::<String>::new());
68 }
69
70 #[test]
71 fn test_compose_build_with_config() {
72 let config = ComposeConfig::new()
73 .file("docker-compose.yml")
74 .project_name("test-project");
75
76 let cmd = ComposeBuildCommand {
77 config: config.clone(),
78 ..Default::default()
79 };
80
81 assert_eq!(cmd.config().project_name, Some("test-project".to_string()));
82 }
83
84 #[test]
85 fn test_compose_build_future_implementation() {
86 let cmd = ComposeBuildCommand {
88 config: ComposeConfig::new(),
89 services: vec!["web".to_string(), "db".to_string()],
90 no_cache: true,
91 pull: true,
92 quiet: false,
93 build_arg: vec![("VERSION".to_string(), "1.0".to_string())],
94 parallel: true,
95 };
96
97 assert_eq!(cmd.build_args(), Vec::<String>::new());
99
100 }
107}