Allow configuration names in application paths

This commit is contained in:
2026-11-02 00:35:37 +00:00
parent 5b03ca6278
commit 1fd0adc571
8 changed files with 73 additions and 35 deletions

View File

@@ -187,8 +187,8 @@ func TestOverrideValidationRejectsPathsOverlapValuesAndProtectedTargets(t *testi
{name: "nonfinite", overrides: []Override{{Path: Keys("scalar"), Value: math.Inf(1), Flag: "--scalar"}}, code: CodeOverrideInvalidValue},
{name: "depth", overrides: []Override{{Path: Keys("nested"), Value: deep, Flag: "--nested"}}, code: CodeOverrideLimitExceeded},
{name: "record bytes", overrides: []Override{{Path: Keys("scalar"), Value: strings.Repeat("x", maxSourceBytes+1), Flag: "--scalar"}}, code: CodeOverrideLimitExceeded},
{name: "directive path", overrides: []Override{{Path: Keys("configkit", "x"), Value: true, Flag: "--directive"}}, code: CodeOverrideDirective},
{name: "directive value", overrides: []Override{{Path: Keys("nested"), Value: map[string]any{"configkit": map[string]any{}}, Flag: "--nested"}}, code: CodeOverrideDirective},
{name: "inheritance path", overrides: []Override{{Path: Keys("extends", "x"), Value: true, Flag: "--directive"}}, code: CodeOverrideDirective},
{name: "inheritance value", overrides: []Override{{Path: Keys("nested"), Value: map[string]any{"extends": map[string]any{}}, Flag: "--nested"}}, code: CodeOverrideDirective},
{name: "version", overrides: []Override{{Path: Keys("version"), Value: "v2", Flag: "--version"}}, code: CodeOverrideVersion},
{name: "version ancestor", overrides: []Override{{Path: Keys("version"), Value: map[string]any{"child": "v2"}, Flag: "--version"}}, code: CodeOverrideVersion},
{name: "label", overrides: []Override{{Path: Keys("scalar"), Value: "x", Flag: "\nCANARY"}}, code: CodeOverrideInvalidLabel},
@@ -206,6 +206,28 @@ func TestOverrideValidationRejectsPathsOverlapValuesAndProtectedTargets(t *testi
}
}
func TestOverrideAcceptsConfigApplicationData(t *testing.T) {
type config struct {
Config map[string]any `yaml:"config"`
ConfigKit map[string]any `yaml:"configkit"`
Nested map[string]any `yaml:"nested"`
}
result, err := testLoad(NoSource(), Options[config]{Overrides: []Override{
{Path: Keys("config", "imports"), Value: "ordinary", Flag: "--imports"},
{Path: Keys("configkit", "sequences"), Value: "ordinary", Flag: "--sequences"},
{Path: Keys("nested"), Value: map[string]any{"config": map[string]any{"sequences": "ordinary"}, "configkit": "old"}, Flag: "--nested"},
}})
if err != nil {
t.Fatal(err)
}
if result.Config.Config["imports"] != "ordinary" || result.Config.ConfigKit["sequences"] != "ordinary" || result.Config.Nested["configkit"] != "old" {
t.Fatalf("overrides = %#v", result.Config)
}
if nested, ok := result.Config.Nested["config"].(map[string]any); !ok || nested["sequences"] != "ordinary" {
t.Fatalf("nested data = %#v", result.Config.Nested)
}
}
func TestOverrideOverlapIndexPreservesFirstAcceptedSource(t *testing.T) {
type config struct {
Nested map[string]any `yaml:"nested"`