lux_lib/lua_rockspec/
deploy.rs1use std::convert::Infallible;
2
3use serde::Deserialize;
4
5use super::{PartialOverride, PerPlatform, PlatformOverridable};
6
7#[derive(Clone, Debug, PartialEq, Deserialize, lux_macros::DisplayAsLuaKV)]
11#[display_lua(key = "deploy")]
12pub struct DeploySpec {
13 #[serde(default = "default_wrap_bin_scripts")]
17 pub wrap_bin_scripts: bool,
18}
19
20impl Default for DeploySpec {
21 fn default() -> Self {
22 Self {
23 wrap_bin_scripts: true,
24 }
25 }
26}
27
28impl PartialOverride for DeploySpec {
29 type Err = Infallible;
30
31 fn apply_overrides(&self, override_spec: &Self) -> Result<Self, Self::Err> {
32 Ok(Self {
33 wrap_bin_scripts: override_spec.wrap_bin_scripts,
34 })
35 }
36}
37
38impl PlatformOverridable for DeploySpec {
39 type Err = Infallible;
40
41 fn on_nil<T>() -> Result<PerPlatform<T>, <Self as PlatformOverridable>::Err>
42 where
43 T: PlatformOverridable,
44 T: Default,
45 {
46 Ok(PerPlatform::default())
47 }
48}
49
50fn default_wrap_bin_scripts() -> bool {
51 true
52}
53
54#[cfg(test)]
55mod tests {
56 use crate::lua_rockspec::DisplayAsLuaKV;
57
58 use super::*;
59
60 fn eval_lua_global<T: serde::de::DeserializeOwned>(code: &str, key: &'static str) -> T {
61 use ottavino::{Closure, Executor, Fuel, Lua};
62 use ottavino_util::serde::from_value;
63 Lua::core()
64 .try_enter(|ctx| {
65 let closure = Closure::load(ctx, None, code.as_bytes())?;
66 let executor = Executor::start(ctx, closure.into(), ());
67 executor.step(ctx, &mut Fuel::with(i32::MAX))?;
68 from_value(ctx.globals().get_value(ctx, key)).map_err(ottavino::Error::from)
69 })
70 .unwrap()
71 }
72
73 #[test]
74 pub fn deploy_spec_roundtrip_true() {
75 let spec = DeploySpec {
76 wrap_bin_scripts: true,
77 };
78 let lua = spec.display_lua().to_string();
79 let restored: DeploySpec = eval_lua_global(&lua, "deploy");
80 assert_eq!(spec, restored);
81 }
82
83 #[test]
84 pub fn deploy_spec_roundtrip_false() {
85 let spec = DeploySpec {
86 wrap_bin_scripts: false,
87 };
88 let lua = spec.display_lua().to_string();
89 let restored: DeploySpec = eval_lua_global(&lua, "deploy");
90 assert_eq!(spec, restored);
91 }
92}