Separate engine loading from inspection state

This commit is contained in:
2026-09-12 16:12:01 +00:00
parent 05812a6ad3
commit b8935e77bd
11 changed files with 120 additions and 25 deletions

View File

@@ -38,7 +38,7 @@ func TestParallelLoadsShareRulesButNotMutableValues(t *testing.T) {
}
const count = 32
results := make([]*Result[independentConfig], count)
results := make([]*testResult[independentConfig], count)
errorsByIndex := make([]error, count)
var group sync.WaitGroup
for index := range count {
@@ -73,6 +73,29 @@ func TestParallelLoadsShareRulesButNotMutableValues(t *testing.T) {
}
}
func TestLoadedConfigurationIsSeparateFromInspection(t *testing.T) {
type configuration struct {
Value string `yaml:"value"`
}
loaded, err := Load[configuration](Bytes("config.yml", []byte("value: original\n")), testSecretBinding())
if err != nil {
t.Fatal(err)
}
if loaded.Inspection == nil {
t.Fatal("inspection is nil")
}
loaded.Config.Value = "mutated"
var effective bytes.Buffer
if err := loaded.Inspection.WriteEffective(&effective); err != nil {
t.Fatal(err)
}
if effective.String() != "value: original\n" {
t.Fatalf("inspection changed with configuration: %q", effective.String())
}
}
func TestConcurrentLoadsOfCopiedReaderSourceHaveOneClaim(t *testing.T) {
source := Reader("shared", strings.NewReader("value: one\n"))
copied := source