Skip to content

Commit ffd77f8

Browse files
committed
add unit test for config override order
1 parent 3a2b94a commit ffd77f8

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

crates/stackable-operator/src/product_config_utils.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,140 @@ mod tests {
10581058
assert_eq!(config, expected);
10591059
}
10601060

1061+
#[rstest]
1062+
#[case(
1063+
HashMap::from([
1064+
("env".to_string(), ROLE_ENV_OVERRIDE.to_string()),
1065+
]),
1066+
HashMap::from([
1067+
("env".to_string(), GROUP_ENV_OVERRIDE.to_string()),
1068+
]),
1069+
BTreeMap::from([
1070+
("cli".to_string(), ROLE_CLI_OVERRIDE.to_string()),
1071+
]),
1072+
BTreeMap::from([
1073+
("cli".to_string(), GROUP_CLI_OVERRIDE.to_string()),
1074+
]),
1075+
HashMap::from([
1076+
("file".to_string(), HashMap::from([
1077+
("file".to_string(), ROLE_CONF_OVERRIDE.to_string())
1078+
]))
1079+
]),
1080+
HashMap::from([
1081+
("file".to_string(), HashMap::from([
1082+
("file".to_string(), GROUP_CONF_OVERRIDE.to_string())
1083+
]))
1084+
]),
1085+
collection ! {
1086+
ROLE_GROUP.to_string() => collection ! {
1087+
PropertyNameKind::Env => collection ! {
1088+
"env".to_string() => Some(GROUP_ENV_OVERRIDE.to_string()),
1089+
},
1090+
PropertyNameKind::Cli => collection ! {
1091+
"cli".to_string() => Some(GROUP_CLI_OVERRIDE.to_string()),
1092+
},
1093+
PropertyNameKind::File("file".to_string()) => collection ! {
1094+
"file".to_string() => Some(GROUP_CONF_OVERRIDE.to_string()),
1095+
}
1096+
}
1097+
}
1098+
)]
1099+
#[case(
1100+
HashMap::from([
1101+
("env".to_string(), ROLE_ENV_OVERRIDE.to_string()),
1102+
]),
1103+
HashMap::from([]),
1104+
BTreeMap::from([
1105+
("cli".to_string(), ROLE_CLI_OVERRIDE.to_string()),
1106+
]),
1107+
BTreeMap::from([]),
1108+
HashMap::from([
1109+
("file".to_string(), HashMap::from([
1110+
("file".to_string(), ROLE_CONF_OVERRIDE.to_string())
1111+
]))
1112+
]),
1113+
HashMap::from([]),
1114+
collection ! {
1115+
ROLE_GROUP.to_string() => collection ! {
1116+
PropertyNameKind::Env => collection ! {
1117+
"env".to_string() => Some(ROLE_ENV_OVERRIDE.to_string()),
1118+
},
1119+
PropertyNameKind::Cli => collection ! {
1120+
"cli".to_string() => Some(ROLE_CLI_OVERRIDE.to_string()),
1121+
},
1122+
PropertyNameKind::File("file".to_string()) => collection ! {
1123+
"file".to_string() => Some(ROLE_CONF_OVERRIDE.to_string()),
1124+
}
1125+
}
1126+
}
1127+
)]
1128+
#[case(
1129+
HashMap::from([]),
1130+
HashMap::from([]),
1131+
BTreeMap::from([]),
1132+
BTreeMap::from([]),
1133+
HashMap::from([]),
1134+
HashMap::from([]),
1135+
collection ! {
1136+
ROLE_GROUP.to_string() => collection ! {
1137+
PropertyNameKind::Env => collection ! {
1138+
"env".to_string() => Some(GROUP_ENV.to_string()),
1139+
},
1140+
PropertyNameKind::Cli => collection ! {
1141+
"cli".to_string() => Some(GROUP_CLI.to_string()),
1142+
},
1143+
PropertyNameKind::File("file".to_string()) => collection ! {
1144+
"file".to_string() => Some(GROUP_CONFIG.to_string()),
1145+
}
1146+
}
1147+
}
1148+
)]
1149+
fn test_order_in_transform_role_to_config(
1150+
#[case] role_env_override: HashMap<String, String>,
1151+
#[case] group_env_override: HashMap<String, String>,
1152+
#[case] role_cli_override: BTreeMap<String, String>,
1153+
#[case] group_cli_override: BTreeMap<String, String>,
1154+
#[case] role_conf_override: HashMap<String, HashMap<String, String>>,
1155+
#[case] group_conf_override: HashMap<String, HashMap<String, String>>,
1156+
#[case] expected: HashMap<
1157+
String,
1158+
HashMap<PropertyNameKind, BTreeMap<String, Option<String>>>,
1159+
>,
1160+
) {
1161+
let role: Role<Box<TestConfig>, TestRoleConfig> = Role {
1162+
config: build_common_config(
1163+
Some(Box::new(TestConfig {
1164+
conf: Some(ROLE_CONFIG.to_string()),
1165+
env: Some(ROLE_ENV.to_string()),
1166+
cli: Some(ROLE_CLI.to_string()),
1167+
})),
1168+
Some(role_conf_override),
1169+
Some(role_env_override),
1170+
Some(role_cli_override),
1171+
),
1172+
role_config: Default::default(),
1173+
role_groups: collection! {"role_group".to_string() => RoleGroup {
1174+
replicas: Some(1),
1175+
config: build_common_config(
1176+
build_test_config(GROUP_CONFIG, GROUP_ENV, GROUP_CLI),
1177+
Some(group_conf_override),
1178+
Some(group_env_override),
1179+
Some(group_cli_override)),
1180+
}},
1181+
};
1182+
1183+
let property_kinds = vec![
1184+
PropertyNameKind::Env,
1185+
PropertyNameKind::Cli,
1186+
PropertyNameKind::File("file".to_string()),
1187+
];
1188+
1189+
let config =
1190+
transform_role_to_config(&String::new(), ROLE_GROUP, &role, &property_kinds).unwrap();
1191+
1192+
assert_eq!(config, expected);
1193+
}
1194+
10611195
#[test]
10621196
fn test_transform_role_to_config_overrides() {
10631197
let role_group = "role_group";

0 commit comments

Comments
 (0)