Skip to main content

anza_xtask/buildkite/
group_step.rs

1use {super::Step, serde::Serialize};
2
3#[derive(Debug, Default, Serialize, PartialEq)]
4pub struct GroupStep {
5    #[serde(skip_serializing_if = "String::is_empty")]
6    #[serde(rename = "group")]
7    pub name: String,
8
9    #[serde(skip_serializing_if = "Vec::is_empty")]
10    pub steps: Vec<Step>,
11}
12
13#[cfg(test)]
14mod tests {
15    use {
16        super::*,
17        crate::buildkite::{test_utils::assert_serialized_json, CommandStep, WaitStep},
18    };
19
20    #[test]
21    fn test_group_step_serialize_json() {
22        assert_serialized_json(
23            &GroupStep {
24                name: String::from("empty group"),
25                steps: vec![
26                    Step::Command(CommandStep {
27                        name: String::from("step 1"),
28                        command: String::from("echo 1"),
29                        ..Default::default()
30                    }),
31                    Step::Wait(WaitStep {}),
32                    Step::Command(CommandStep {
33                        name: String::from("step 2"),
34                        command: String::from("echo 2"),
35                        ..Default::default()
36                    }),
37                ],
38            },
39            r#"{
40                "group": "empty group",
41                "steps": [
42                    {"name": "step 1", "command": "echo 1"},
43                    {"wait": "~"},
44                    {"name": "step 2", "command": "echo 2"}
45                ]
46            }"#,
47        );
48    }
49}