@@ -17,7 +17,7 @@ pub use github::GitHubConfig;
1717pub use host:: HostConfig ;
1818pub use machine:: { Artifact , MachineConfig , NetworkInterface , Repository , SeedBasePolicy } ;
1919
20- #[ derive( Deserialize ) ]
20+ #[ derive( Debug , Deserialize , PartialEq ) ]
2121#[ serde( deny_unknown_fields) ]
2222pub struct ConfigFile {
2323 pub github : GitHubConfig ,
@@ -170,3 +170,120 @@ impl Config {
170170 self . inner . lock ( ) . unwrap ( ) . get ( )
171171 }
172172}
173+
174+ #[ cfg( test) ]
175+ mod tests {
176+ use super :: ConfigFile ;
177+
178+ const CONFIG_NESTED : & [ u8 ] = br#"
179+ host:
180+ base_dir: /srv/forrest
181+ ram: 120G
182+
183+ github:
184+ app_id: 1234
185+ jwt_key_file: key.pem
186+ polling_interval: 15m
187+ webhook_secret: Some super secret text
188+
189+ .machines:
190+ machine-small: &machine-small
191+ setup_template:
192+ path: /etc/forrest/templates/generic
193+ parameters:
194+ RUNNER_VERSION: "2.318.0"
195+ RUNNER_HASH: "28ed88e4cedf0fc93201a901e392a70463dbd0213f2ce9d57a4ab495027f3e2f"
196+ base_image: /srv/forrest/images/debian-12-generic-amd64.raw
197+ cpus: 4
198+ disk: 16G
199+ ram: 4G
200+ machine-medium: &machine-medium
201+ << : *machine-small
202+ cpus: 8
203+ disk: 32G
204+ ram: 8G
205+
206+ repositories:
207+ hnez:
208+ forrest-images:
209+ persistence_token: <PERSISTENCE_TOKEN>
210+ machines:
211+ debian-base:
212+ << : *machine-small
213+ use_base: always
214+ debian-yocto:
215+ << : *machine-small
216+ base_machine: hnez/forrest-images/debian-base
217+ use_base: always
218+
219+ forrest-test:
220+ machines:
221+ test-debian:
222+ << : *machine-medium
223+ base_machine: hnez/forrest-images/debian-base
224+ "# ;
225+
226+ const CONFIG_FLAT : & [ u8 ] = br#"
227+ host:
228+ base_dir: /srv/forrest
229+ ram: 120G
230+
231+ github:
232+ app_id: 1234
233+ jwt_key_file: key.pem
234+ polling_interval: 15m
235+ webhook_secret: Some super secret text
236+
237+ repositories:
238+ hnez:
239+ forrest-images:
240+ persistence_token: <PERSISTENCE_TOKEN>
241+ machines:
242+ debian-base:
243+ setup_template:
244+ path: /etc/forrest/templates/generic
245+ parameters:
246+ RUNNER_VERSION: "2.318.0"
247+ RUNNER_HASH: "28ed88e4cedf0fc93201a901e392a70463dbd0213f2ce9d57a4ab495027f3e2f"
248+ base_image: /srv/forrest/images/debian-12-generic-amd64.raw
249+ cpus: 4
250+ disk: 16G
251+ ram: 4G
252+ use_base: always
253+ debian-yocto:
254+ setup_template:
255+ path: /etc/forrest/templates/generic
256+ parameters:
257+ RUNNER_VERSION: "2.318.0"
258+ RUNNER_HASH: "28ed88e4cedf0fc93201a901e392a70463dbd0213f2ce9d57a4ab495027f3e2f"
259+ base_image: /srv/forrest/images/debian-12-generic-amd64.raw
260+ cpus: 4
261+ disk: 16G
262+ ram: 4G
263+ base_machine: hnez/forrest-images/debian-base
264+ use_base: always
265+
266+ forrest-test:
267+ machines:
268+ test-debian:
269+ setup_template:
270+ path: /etc/forrest/templates/generic
271+ parameters:
272+ RUNNER_VERSION: "2.318.0"
273+ RUNNER_HASH: "28ed88e4cedf0fc93201a901e392a70463dbd0213f2ce9d57a4ab495027f3e2f"
274+ base_image: /srv/forrest/images/debian-12-generic-amd64.raw
275+ cpus: 8
276+ disk: 32G
277+ ram: 8G
278+ base_machine: hnez/forrest-images/debian-base
279+
280+ "# ;
281+
282+ #[ test]
283+ fn nested_snippets ( ) {
284+ let config_file_nested = ConfigFile :: from_reader ( CONFIG_NESTED ) . unwrap ( ) ;
285+ let config_file_flat = ConfigFile :: from_reader ( CONFIG_FLAT ) . unwrap ( ) ;
286+
287+ assert_eq ! ( config_file_nested, config_file_flat) ;
288+ }
289+ }
0 commit comments