anza_xtask/buildkite/
command_step.rs1use {serde::Serialize, std::collections::HashMap};
2
3#[derive(Debug, Serialize, Default, PartialEq)]
4pub struct CommandStep {
5 #[serde(skip_serializing_if = "String::is_empty")]
6 pub name: String,
7
8 #[serde(skip_serializing_if = "String::is_empty")]
9 pub command: String,
10
11 #[serde(skip_serializing_if = "Vec::is_empty")]
12 pub commands: Vec<String>,
13
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub cancel_on_build_failing: Option<bool>,
16
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub soft_fail: Option<bool>,
19
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub agents: Option<HashMap<String, String>>,
22
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub timeout_in_minutes: Option<i64>,
25
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub retry: Option<HashMap<String, String>>,
28
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub env: Option<HashMap<String, String>>,
31}
32
33#[cfg(test)]
34mod tests {
35 use {super::*, crate::buildkite::test_utils::assert_serialized_json};
36
37 #[test]
38 fn test_command_step_basic_name_only() {
39 assert_serialized_json(
40 &CommandStep {
41 name: String::from("basic test"),
42 ..Default::default()
43 },
44 r#"{
45 "name": "basic test"
46 }"#,
47 );
48 }
49
50 #[test]
51 fn test_command_step_full() {
52 assert_serialized_json(
53 &CommandStep {
54 name: String::from("full command step"),
55 command: String::from("npm test"),
56 cancel_on_build_failing: Some(true),
57 soft_fail: Some(false),
58 agents: Some(HashMap::from([(
59 String::from("queue"),
60 String::from("test"),
61 )])),
62 timeout_in_minutes: Some(15),
63 retry: Some(HashMap::from([(
64 String::from("automatic"),
65 String::from("true"),
66 )])),
67 env: Some(HashMap::from([(
68 String::from("FETCH_COVERAGE_ENV"),
69 String::from("true"),
70 )])),
71 ..Default::default()
72 },
73 r#"{
74 "name": "full command step",
75 "command": "npm test",
76 "cancel_on_build_failing": true,
77 "soft_fail": false,
78 "agents": {"queue": "test"},
79 "timeout_in_minutes": 15,
80 "retry": {"automatic": "true"},
81 "env": {"FETCH_COVERAGE_ENV": "true"}
82 }"#,
83 );
84 }
85}