-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce Stack, with weak validation (#789)
* Reintroduce Stack (but with weaker validation) * Reintroduce stacks into deserialization tests * Add changelog entry for stack reintroduction * Skip serializing empty mixins Co-authored-by: Ed Morley <[email protected]> --------- Co-authored-by: Ed Morley <[email protected]>
- Loading branch information
1 parent
b89c4ae
commit dc95de5
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use serde::Deserialize; | ||
|
||
// Stacks are deprecated in Buildpack API 0.10, and libcnb.rs effectively | ||
// ignores them. However, they are still supported by the Buildpack API, so | ||
// libcnb should continue to allow them to exist in buildpack.toml. | ||
#[derive(Deserialize, Debug, Eq, PartialEq)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Stack { | ||
pub id: String, | ||
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub mixins: Vec<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn deserialize_specific_stack_without_mixins() { | ||
let toml_str = r#" | ||
id = "heroku-20" | ||
"#; | ||
assert_eq!( | ||
toml::from_str::<Stack>(toml_str), | ||
Ok(Stack { | ||
id: String::from("heroku-20"), | ||
mixins: Vec::new() | ||
}), | ||
); | ||
} | ||
|
||
#[test] | ||
fn deserialize_specific_stack_with_mixins() { | ||
let toml_str = r#" | ||
id = "io.buildpacks.stacks.focal" | ||
mixins = ["build:jq", "wget"] | ||
"#; | ||
assert_eq!( | ||
toml::from_str::<Stack>(toml_str), | ||
Ok(Stack { | ||
id: String::from("io.buildpacks.stacks.focal"), | ||
mixins: vec![String::from("build:jq"), String::from("wget")] | ||
}), | ||
); | ||
} | ||
|
||
#[test] | ||
fn deserialize_any_stack() { | ||
let toml_str = r#" | ||
id = "*" | ||
"#; | ||
assert_eq!( | ||
toml::from_str::<Stack>(toml_str), | ||
Ok(Stack { | ||
id: String::from("*"), | ||
mixins: vec![], | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters