44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package configkit
|
|
|
|
import "testing"
|
|
|
|
func TestFacadeResolutionRecordingIntents(t *testing.T) {
|
|
type configuration struct {
|
|
Derived string `yaml:"derived"`
|
|
Normalized string `yaml:"normalized"`
|
|
}
|
|
|
|
result, err := Load(Bytes("recording.yml", []byte("derived: explicit\nnormalized: before\n")), Options[configuration]{
|
|
Definition: Definition[configuration]{Resolve: func(value *configuration, resolution *Resolution) error {
|
|
value.Derived = "changed explicit input"
|
|
resolution.RecordDerivedDefault(Keys("derived"), "derive explicit input")
|
|
value.Normalized = "after"
|
|
resolution.RecordNormalization(Keys("normalized"), "normalize configured input")
|
|
return nil
|
|
}},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
for _, test := range []struct {
|
|
path Path
|
|
kind ChangeKind
|
|
}{
|
|
{path: Keys("derived"), kind: ChangeDerivedDefault},
|
|
{path: Keys("normalized"), kind: ChangeNormalization},
|
|
} {
|
|
info, ok := result.Metadata().Lookup(test.path)
|
|
if !ok || info.Origin.Operation != test.kind {
|
|
t.Errorf("metadata %s = %#v, %v; want operation %q", test.path, info, ok, test.kind)
|
|
}
|
|
history := result.Metadata().History(test.path)
|
|
if len(history) == 0 || history[len(history)-1].Origin.Operation != test.kind {
|
|
t.Errorf("history %s = %#v; want final operation %q", test.path, history, test.kind)
|
|
}
|
|
}
|
|
if !result.Metadata().IsExplicit(Keys("derived")) {
|
|
t.Fatal("recording a derived default suppressed explicit-input provenance")
|
|
}
|
|
}
|