xianyun_executor/exec/
noop.rs1use std::path::PathBuf;
6
7use std::time::Duration;
8
9use super::{CommandRunner, ExecError, ExecResult, ExecStreamedOpts, Options};
10
11#[derive(Debug, thiserror::Error)]
13#[error("executor: command execution not available in this context")]
14pub struct ErrNotImplemented;
15
16#[derive(Default)]
18pub struct NoopClient;
19
20impl NoopClient {
21 pub fn new() -> Self {
22 Self
23 }
24}
25
26impl CommandRunner for NoopClient {
27 fn run(&self, _name: &str, _args: &[String], _opts: Option<Options>) -> ExecResult {
28 ExecResult {
29 stdout: Vec::new(),
30 stderr: Vec::new(),
31 exit_code: 1,
32 error: Some(ExecError::RunFailed(ErrNotImplemented.to_string())),
33 duration: Duration::ZERO,
34 }
35 }
36
37 fn read_stdout(&self, _name: &str, _args: &[String]) -> Result<String, ExecError> {
38 Err(ExecError::RunFailed(ErrNotImplemented.to_string()))
39 }
40
41 fn run_sudo(&self, _name: &str, _args: &[String]) -> Result<(), ExecError> {
42 Err(ExecError::RunFailed(ErrNotImplemented.to_string()))
43 }
44
45 fn check(&self, _name: &str, _args: &[String]) -> Result<bool, ExecError> {
46 Err(ExecError::RunFailed(ErrNotImplemented.to_string()))
47 }
48
49 fn exec_streamed_command(
50 &self,
51 _opts: Option<ExecStreamedOpts>,
52 _name: &str,
53 _args: &[String],
54 ) -> Result<(), ExecError> {
55 Err(ExecError::RunFailed(ErrNotImplemented.to_string()))
56 }
57
58 fn look_path(&self, _file: &str) -> Result<PathBuf, ExecError> {
59 Err(ExecError::LookPathFailed(ErrNotImplemented.to_string()))
60 }
61
62 fn run_in_repository(
63 &self,
64 _repo_dir: &str,
65 _name: &str,
66 _args: &[String],
67 _opts: Option<ExecStreamedOpts>,
68 ) -> Result<(), ExecError> {
69 Err(ExecError::RunFailed(ErrNotImplemented.to_string()))
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn run() {
79 let c = NoopClient::new();
80 let result = c.run("echo", &["hello".into()], None);
81 assert!(result.error.is_some());
82 assert_eq!(result.exit_code, 1);
83 }
84
85 #[test]
86 fn read_stdout() {
87 let c = NoopClient::new();
88 let err = c.read_stdout("echo", &["hello".into()]).unwrap_err();
89 let _ = err;
90 }
91
92 #[test]
93 fn exec_streamed_command() {
94 let c = NoopClient::new();
95 let err = c.exec_streamed_command(None, "echo", &["hello".into()]);
96 assert!(err.is_err());
97 }
98
99 #[test]
100 fn look_path() {
101 let c = NoopClient::new();
102 let err = c.look_path("echo").unwrap_err();
103 let _ = err;
104 }
105
106 #[test]
107 fn run_in_repository() {
108 let c = NoopClient::new();
109 let err = c.run_in_repository("", "echo", &["hello".into()], None);
110 assert!(err.is_err());
111 }
112
113 #[test]
114 fn check() {
115 let c = NoopClient::new();
116 let err = c.check("echo", &["hello".into()]).unwrap_err();
117 let _ = err;
118 }
119}