Use focused native configuration inspection
This commit is contained in:
@@ -53,6 +53,50 @@ func TestCaptureUsesEffectiveSourceContexts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapturedInspectionUsesNativeView(t *testing.T) {
|
||||
type anotherApplication struct {
|
||||
PromptKit promptkit.Settings `yaml:"promptkit"`
|
||||
Sibling int `yaml:"sibling"`
|
||||
}
|
||||
definition := promptkit.Configure(configkit.Definition[application]{}, func(value *application) *promptkit.Settings { return &value.PromptKit })
|
||||
first, err := configkit.Load(configkit.Bytes("first", []byte("promptkit: {application_field: first}\n")), configkit.Options[application]{Definition: definition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
secondDefinition := promptkit.Configure(configkit.Definition[anotherApplication]{}, func(value *anotherApplication) *promptkit.Settings { return &value.PromptKit })
|
||||
second, err := configkit.Load(configkit.Bytes("second", []byte("promptkit: {application_field: second}\n")), configkit.Options[anotherApplication]{Definition: secondDefinition})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
leftView, _ := first.InspectSubtree(configkit.Keys("promptkit"))
|
||||
rightView, _ := second.InspectSubtree(configkit.Keys("promptkit"))
|
||||
diagnostics := []configkit.Diagnostic{{Message: "warning", Primary: &configkit.Location{SourceID: "first"}, Related: []configkit.Location{{SourceID: "related"}}}}
|
||||
left, err := configuration.Capture(&first.Config.PromptKit, leftView, diagnostics)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
right, err := configuration.Capture(&second.Config.PromptKit, rightView, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
diagnostics[0].Primary.SourceID = "changed"
|
||||
diagnostics[0].Related[0].SourceID = "changed"
|
||||
got := left.Inspection().Diagnostics()
|
||||
if got[0].Primary.SourceID != "first" || got[0].Related[0].SourceID != "related" {
|
||||
t.Fatalf("captured diagnostics = %+v", got)
|
||||
}
|
||||
got[0].Primary.SourceID = "again"
|
||||
got[0].Related[0].SourceID = "again"
|
||||
got = left.Inspection().Diagnostics()
|
||||
if got[0].Primary.SourceID != "first" || got[0].Related[0].SourceID != "related" {
|
||||
t.Fatalf("returned diagnostics aliased: %+v", got)
|
||||
}
|
||||
differences, err := configuration.Diff(left.Inspection(), right.Inspection())
|
||||
if err != nil || len(differences) == 0 || len(left.Inspection().HistoricalPaths()) == 0 {
|
||||
t.Fatalf("diff = %+v, %v", differences, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCaptureOwnsEffectiveResources(t *testing.T) {
|
||||
definition := promptkit.Configure(configkit.Definition[application]{}, func(value *application) *promptkit.Settings { return &value.PromptKit })
|
||||
result, err := configkit.Load(configkit.Bytes("application", []byte(`other: application
|
||||
|
||||
Reference in New Issue
Block a user