codex_config/
test_support.rs1use crate::CloudConfigBundle;
6use crate::CloudConfigBundleLoader;
7use crate::CloudConfigFragment;
8use crate::CloudRequirementsFragment;
9
10#[derive(Debug, Clone, Default)]
11pub struct CloudConfigBundleFixture {
12 bundle: CloudConfigBundle,
13}
14
15impl CloudConfigBundleFixture {
16 pub fn enterprise_requirement(contents: impl Into<String>) -> Self {
17 Self::default().add_enterprise_requirement(contents)
18 }
19
20 pub fn enterprise_config(contents: impl Into<String>) -> Self {
21 Self::default().add_enterprise_config(contents)
22 }
23
24 pub fn loader_with_enterprise_requirement(
25 contents: impl Into<String>,
26 ) -> CloudConfigBundleLoader {
27 Self::enterprise_requirement(contents).into_loader()
28 }
29
30 pub fn loader_with_enterprise_config(contents: impl Into<String>) -> CloudConfigBundleLoader {
31 Self::enterprise_config(contents).into_loader()
32 }
33
34 pub fn add_enterprise_requirement(mut self, contents: impl Into<String>) -> Self {
35 let index = self.bundle.requirements_toml.enterprise_managed.len() + 1;
36 self.bundle
37 .requirements_toml
38 .enterprise_managed
39 .push(CloudRequirementsFragment {
40 id: format!("req_{index}"),
41 name: if index == 1 {
42 "Base requirements".to_string()
43 } else {
44 format!("Requirements {index}")
45 },
46 contents: contents.into(),
47 });
48 self
49 }
50
51 pub fn add_enterprise_config(mut self, contents: impl Into<String>) -> Self {
52 let index = self.bundle.config_toml.enterprise_managed.len() + 1;
53 self.bundle
54 .config_toml
55 .enterprise_managed
56 .push(CloudConfigFragment {
57 id: format!("cfg_{index}"),
58 name: if index == 1 {
59 "Base config".to_string()
60 } else {
61 format!("Config {index}")
62 },
63 contents: contents.into(),
64 });
65 self
66 }
67
68 pub fn into_bundle(self) -> CloudConfigBundle {
69 self.bundle
70 }
71
72 pub fn into_loader(self) -> CloudConfigBundleLoader {
73 let bundle = self.into_bundle();
74 CloudConfigBundleLoader::new(async move { Ok(Some(bundle)) })
75 }
76}
77
78#[cfg(test)]
79#[path = "test_support_tests.rs"]
80mod tests;