buildkit_frontend/options/
mod.rs1mod default;
2mod deserializer;
3
4pub use self::default::Options;
5pub use self::deserializer::from_env;
6
7pub mod common;
8
9#[cfg(test)]
10mod tests {
11 use std::path::PathBuf;
12
13 use super::*;
14 use serde::Deserialize;
15
16 #[derive(Debug, Deserialize, PartialEq)]
17 #[serde(untagged)]
18 #[serde(field_identifier, rename_all = "lowercase")]
19 enum Debug {
20 All,
21 LLB,
22 Frontend,
23 }
24
25 #[derive(Debug, Deserialize, PartialEq)]
26 #[serde(rename_all = "kebab-case")]
27 struct CustomOptions {
28 filename: Option<PathBuf>,
29 verbosity: u32,
30
31 #[serde(default)]
32 debug: Vec<Debug>,
33
34 #[serde(default)]
35 cache_imports: Vec<common::CacheOptionsEntry>,
36 }
37
38 #[test]
39 fn custom_options() {
40 let env = vec![
41 (
42 "BUILDKIT_FRONTEND_OPT_0".into(),
43 "filename=/path/to/Dockerfile".into(),
44 ),
45 (
46 "BUILDKIT_FRONTEND_OPT_1".into(),
47 "debug=llb,frontend".into(),
48 ),
49 (
50 "BUILDKIT_FRONTEND_OPT_2".into(),
51 r#"cache-imports=[{"Type":"local","Attrs":{"src":"cache"}}]"#.into(),
52 ),
53 (
54 "BUILDKIT_FRONTEND_OPT_3".into(),
55 "verbosity=12345678".into(),
56 ),
57 ];
58
59 assert_eq!(
60 from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
61 CustomOptions {
62 filename: Some(PathBuf::from("/path/to/Dockerfile")),
63 verbosity: 12_345_678,
64
65 debug: vec![Debug::LLB, Debug::Frontend],
66
67 cache_imports: vec![common::CacheOptionsEntry {
68 cache_type: common::CacheType::Local,
69 attrs: vec![("src".into(), "cache".into())].into_iter().collect()
70 }],
71 }
72 );
73 }
74
75 #[test]
76 fn env_variable_names() {
77 let env = vec![
78 (
79 "ANOTHER_OPT_0".into(),
80 "filename=/path/to/Dockerfile".into(),
81 ),
82 (
83 "ANOTHER_OPT_2".into(),
84 r#"cache-imports=[{"Type":"local","Attrs":{"src":"cache"}}]"#.into(),
85 ),
86 ("BUILDKIT_FRONTEND_OPT_1".into(), "debug=all".into()),
87 (
88 "BUILDKIT_FRONTEND_OPT_2".into(),
89 "verbosity=12345678".into(),
90 ),
91 ];
92
93 assert_eq!(
94 from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
95 CustomOptions {
96 filename: None,
97 verbosity: 12_345_678,
98 debug: vec![Debug::All],
99 cache_imports: vec![],
100 }
101 );
102 }
103
104 #[test]
105 fn empty_cache() {
106 let env = vec![
107 ("BUILDKIT_FRONTEND_OPT_1".into(), "cache-imports=".into()),
108 (
109 "BUILDKIT_FRONTEND_OPT_2".into(),
110 "verbosity=12345678".into(),
111 ),
112 ];
113
114 assert_eq!(
115 from_env::<CustomOptions, _>(env.into_iter()).unwrap(),
116 CustomOptions {
117 filename: None,
118 verbosity: 12_345_678,
119 debug: vec![],
120 cache_imports: vec![],
121 }
122 );
123 }
124}