Add configuration comparison capability contract
This commit is contained in:
@@ -112,9 +112,20 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
for _, issue := range scope.issues {
|
||||
prepared.issues = append(prepared.issues, fmt.Errorf("configuration scope %q: %w", scope.Name, issue))
|
||||
}
|
||||
if len(scope.Operations) > 0 && scope.Acquire == nil {
|
||||
requiresAcquire, requiresCompare := false, false
|
||||
for _, operation := range scope.Operations {
|
||||
if operation == Diff {
|
||||
requiresCompare = true
|
||||
} else {
|
||||
requiresAcquire = true
|
||||
}
|
||||
}
|
||||
if requiresAcquire && scope.Acquire == nil {
|
||||
prepared.issues = append(prepared.issues, fmt.Errorf("configuration scope %q declares operations without an acquisition callback", scope.Name))
|
||||
}
|
||||
if requiresCompare && scope.Compare == nil {
|
||||
prepared.issues = append(prepared.issues, fmt.Errorf("configuration scope %q declares diff without a comparison callback", scope.Name))
|
||||
}
|
||||
prepared.scopes = append(prepared.scopes, &preparedScope[I, S]{scope: scope})
|
||||
}
|
||||
sort.SliceStable(prepared.scopes, func(i, j int) bool {
|
||||
@@ -156,7 +167,7 @@ func captureSuite[I, S any](suite Suite[I, S]) *preparedSuite[I, S] {
|
||||
}
|
||||
}
|
||||
|
||||
for _, operation := range []Operation{Validate, Show, Sources, Explain} {
|
||||
for _, operation := range []Operation{Validate, Show, Sources, Explain, Diff} {
|
||||
for _, scope := range prepared.scopes {
|
||||
if containsOperation(scope.scope.Operations, operation) {
|
||||
prepared.operations = append(prepared.operations, operation)
|
||||
@@ -185,14 +196,14 @@ func normalizeOperations(operations []Operation, issues *[]error, scope string)
|
||||
seen := make(map[Operation]struct{}, len(operations))
|
||||
for _, operation := range operations {
|
||||
switch operation {
|
||||
case Validate, Show, Sources, Explain:
|
||||
case Validate, Show, Sources, Explain, Diff:
|
||||
default:
|
||||
*issues = append(*issues, fmt.Errorf("configuration scope %q declares unknown operation %q", scope, operation))
|
||||
}
|
||||
seen[operation] = struct{}{}
|
||||
}
|
||||
ordered := make([]Operation, 0, len(seen))
|
||||
for _, operation := range []Operation{Validate, Show, Sources, Explain} {
|
||||
for _, operation := range []Operation{Validate, Show, Sources, Explain, Diff} {
|
||||
if _, exists := seen[operation]; exists {
|
||||
ordered = append(ordered, operation)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user