Skip to content

Commit

Permalink
fix: unification stmt override (#1435)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Jun 25, 2024
1 parent 50921fc commit 82bff23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions kclvm/query/src/override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ impl<'ctx> MutSelfMutWalker<'ctx> for OverrideTransformer {

// Unification is only support to override the schema expression.
if let ast::Expr::Schema(schema_expr) = value.node {
self.has_override = true;
unification_stmt.value =
Box::new(ast::Node::dummy_node(schema_expr));
if self.field_paths.len() == 0 {
self.has_override = true;
unification_stmt.value =
Box::new(ast::Node::dummy_node(schema_expr));
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions kclvm/query/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ fn test_override_file_config() {
"appConfiguration.overQuota=False".to_string(),
"appConfiguration.probe={periodSeconds=20}".to_string(),
"appConfiguration.resource-".to_string(),
"appConfiguration.svc=s.Service {}".to_string(),
"appConfigurationUnification.image=\"kcl/kcl:v0.1\"".to_string(),
r#"appConfigurationUnification.mainContainer.name="override_name""#.to_string(),
"appConfigurationUnification.labels.key.key=\"override_value\"".to_string(),
"appConfigurationUnification.overQuota=False".to_string(),
"appConfigurationUnification.resource.cpu-".to_string(),
"appConfigurationUnification.svc=s.Service {}".to_string(),
"config.x:1".to_string(),
"config.y=1".to_string(),
"config.z+=[1,2,3]".to_string(),
Expand All @@ -120,7 +122,7 @@ fn test_override_file_config() {
"var3+=[1,2,3]".to_string(),
"var4:AppConfiguration {image:'image'}".to_string(),
];
let import_paths = vec![];
let import_paths = vec!["service as s".to_string()];

let mut cargo_file_path = PathBuf::from(CARGO_FILE_PATH);
cargo_file_path.push("src/test_data/config.k");
Expand All @@ -133,7 +135,9 @@ fn test_override_file_config() {
let expected_code = print_ast_module(&module);
assert_eq!(
expected_code,
r#"schema Main:
r#"import service as s
schema Main:
name?: str
env?: [{str:}]
Expand Down Expand Up @@ -167,6 +171,7 @@ appConfiguration = AppConfiguration {
overQuota = False
overQuota = False
probe: {periodSeconds = 20}
svc = s.Service {}
}
appConfigurationUnification: AppConfiguration {
Expand All @@ -181,6 +186,7 @@ appConfigurationUnification: AppConfiguration {
}
mainContainer: Main {name: "override_name"}
overQuota: False
svc = s.Service {}
}
config = {x: 1, y = 1, z += [1, 2, 3]}
var1 = 1
Expand Down

0 comments on commit 82bff23

Please sign in to comment.