Skip to content

Commit f0665f1

Browse files
committed
test(compose): cover secret and config merge in include.rs
The include merge for secrets and configs (including the parent-wins conflict path) was untested. Add merge-and-conflict tests for both. Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
1 parent e5f697f commit f0665f1

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

internal/compose/include.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,47 @@ mod tests {
9191
assert!(target.networks.contains_key("backend"));
9292
}
9393

94+
#[test]
95+
fn merge_adds_and_parent_wins_on_secret_conflict() {
96+
use super::super::types::SecretConfig;
97+
let secret = |f: &str| SecretConfig {
98+
file: Some(f.to_string()),
99+
..Default::default()
100+
};
101+
let mut target = ComposeFile::default();
102+
target
103+
.secrets
104+
.insert("tok".to_string(), secret("parent.txt"));
105+
let mut other = ComposeFile::default();
106+
other.secrets.insert("tok".to_string(), secret("child.txt"));
107+
other.secrets.insert("extra".to_string(), secret("e.txt"));
108+
merge_compose_file(&mut target, other);
109+
// Parent wins on conflict; the included-only secret is added.
110+
assert_eq!(target.secrets["tok"].file.as_deref(), Some("parent.txt"));
111+
assert_eq!(target.secrets["extra"].file.as_deref(), Some("e.txt"));
112+
}
113+
114+
#[test]
115+
fn merge_adds_and_parent_wins_on_config_conflict() {
116+
use super::super::types::ConfigConfig;
117+
let config = |f: &str| ConfigConfig {
118+
file: Some(f.to_string()),
119+
..Default::default()
120+
};
121+
let mut target = ComposeFile::default();
122+
target
123+
.configs
124+
.insert("cfg".to_string(), config("parent.conf"));
125+
let mut other = ComposeFile::default();
126+
other
127+
.configs
128+
.insert("cfg".to_string(), config("child.conf"));
129+
other.configs.insert("only".to_string(), config("o.conf"));
130+
merge_compose_file(&mut target, other);
131+
assert_eq!(target.configs["cfg"].file.as_deref(), Some("parent.conf"));
132+
assert_eq!(target.configs["only"].file.as_deref(), Some("o.conf"));
133+
}
134+
94135
#[test]
95136
fn merge_empty_other_is_noop() {
96137
let mut target = ComposeFile::default();

0 commit comments

Comments
 (0)