Share immutable backend defaults during profile capture
This commit is contained in:
@@ -64,6 +64,45 @@ func TestOverlayProviderMapOwnsInputsAndReplacesValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfilesWithSharedDefaultsRemainIsolatedAtLookup(t *testing.T) {
|
||||
state, err := load(mapping("shared defaults", map[string]any{
|
||||
"backends": []any{map[string]any{"id": "backend", "endpoint": "https://example.test/v1",
|
||||
"extra_params": map[string]any{"nested": map[string]any{"value": "backend"}}}},
|
||||
"profiles": []any{
|
||||
map[string]any{"id": "first", "backend": "backend"},
|
||||
map[string]any{"id": "second", "backend": "backend"},
|
||||
map[string]any{"id": "overlay", "backend": "backend", "extra_params": map[string]any{"nested": map[string]any{"value": "profile"}}},
|
||||
},
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, id := range []string{"first", "second", "overlay"} {
|
||||
profile, err := state.GetProfile(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := "backend"
|
||||
if id == "overlay" {
|
||||
want = "profile"
|
||||
}
|
||||
if profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] != want {
|
||||
t.Fatalf("%s defaults changed: %+v", id, profile)
|
||||
}
|
||||
profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] = "caller mutation"
|
||||
}
|
||||
backend, err := state.GetBackend("backend")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
backend.ExtraParams["nested"].(map[string]any)["value"] = "backend caller mutation"
|
||||
profile, err := state.GetProfile(ctx, "first")
|
||||
if err != nil || profile.ResolvedTarget.ExtraParams["nested"].(map[string]any)["value"] != "backend" {
|
||||
t.Fatalf("lookup mutation changed retained defaults: %+v, %v", profile, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestCompletesLoadedPartialProfile(t *testing.T) {
|
||||
state, err := load(mapping("partial profile", map[string]any{
|
||||
"profiles": []any{map[string]any{"id": "partial"}},
|
||||
|
||||
Reference in New Issue
Block a user