libcnb_data/buildpack/
stack.rs

1use serde::Deserialize;
2
3// Stacks are deprecated in Buildpack API 0.10, and libcnb.rs effectively
4// ignores them. However, they are still supported by the Buildpack API, so
5// libcnb should continue to allow them to exist in buildpack.toml.
6#[derive(Deserialize, Debug, Eq, PartialEq)]
7#[serde(deny_unknown_fields)]
8pub struct Stack {
9    pub id: String,
10    #[serde(default, skip_serializing_if = "Vec::is_empty")]
11    pub mixins: Vec<String>,
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17
18    #[test]
19    fn deserialize_specific_stack_without_mixins() {
20        let toml_str = r#"
21id = "heroku-20"
22"#;
23        assert_eq!(
24            toml::from_str::<Stack>(toml_str),
25            Ok(Stack {
26                id: String::from("heroku-20"),
27                mixins: Vec::new()
28            }),
29        );
30    }
31
32    #[test]
33    fn deserialize_specific_stack_with_mixins() {
34        let toml_str = r#"
35id = "io.buildpacks.stacks.focal"
36mixins = ["build:jq", "wget"]
37"#;
38        assert_eq!(
39            toml::from_str::<Stack>(toml_str),
40            Ok(Stack {
41                id: String::from("io.buildpacks.stacks.focal"),
42                mixins: vec![String::from("build:jq"), String::from("wget")]
43            }),
44        );
45    }
46
47    #[test]
48    fn deserialize_any_stack() {
49        let toml_str = r#"
50id = "*"
51"#;
52        assert_eq!(
53            toml::from_str::<Stack>(toml_str),
54            Ok(Stack {
55                id: String::from("*"),
56                mixins: Vec::new(),
57            }),
58        );
59    }
60}