1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! The `conductor stop` command.

use command_runner::{Command, CommandRunner};
#[cfg(test)]
use command_runner::TestCommandRunner;
use errors::*;
use ovr::Override;
use project::Project;

/// We implement `conductor stop` with a trait so we put it in its own module.
pub trait CommandStop {
    /// Stop all the images associated with a project.
    fn stop<CR>(&self, runner: &CR, ovr: &Override) -> Result<()>
        where CR: CommandRunner;
}

impl CommandStop for Project {
    fn stop<CR>(&self, runner: &CR, ovr: &Override) -> Result<()>
        where CR: CommandRunner
    {
        for pod in self.pods() {
            try!(runner.build("docker-compose")
                .args(&try!(pod.compose_args(self, ovr)))
                .arg("stop")
                .exec());
        }
        Ok(())
    }
}

#[test]
fn runs_docker_compose_stop_on_all_pods() {
    use env_logger;
    let _ = env_logger::init();
    let proj = Project::from_example("hello").unwrap();
    let ovr = proj.ovr("development").unwrap();
    let runner = TestCommandRunner::new();
    proj.output(ovr).unwrap();
    proj.stop(&runner, ovr).unwrap();
    assert_ran!(runner, {
        ["docker-compose",
         "-p",
         "hello",
         "-f",
         proj.output_dir().join("pods/frontend.yml"),
         "stop"]
    });
    proj.remove_test_output().unwrap();
}