Skip to content

Commit 35fea83

Browse files
authored
Merge pull request #111 from tampakrap/fix_sort_resources
fix(assertions): sort map keys in findResources for deterministic output
2 parents 61c6ff2 + 1cf78c4 commit 35fea83

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

internal/testexecution/runner/assertions_xprin.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package runner
2020
import (
2121
"fmt"
2222
"path/filepath"
23+
"sort"
2324
"strings"
2425

2526
"github.com/crossplane-contrib/xprin/internal/api"
@@ -435,7 +436,17 @@ func (e *assertionExecutor) findResources(pattern string) ([]*unstructured.Unstr
435436
pattern += "/*"
436437
}
437438

438-
for resourceIdentifier, resourcePath := range e.outputs.Rendered {
439+
// Extract keys and sort them to get deterministic ordering in assertions
440+
keys := make([]string, 0, len(e.outputs.Rendered))
441+
for k := range e.outputs.Rendered {
442+
keys = append(keys, k)
443+
}
444+
445+
sort.Strings(keys)
446+
447+
for _, resourceIdentifier := range keys {
448+
resourcePath := e.outputs.Rendered[resourceIdentifier]
449+
439450
isMatched, err := filepath.Match(pattern, resourceIdentifier)
440451
if err != nil {
441452
return nil, fmt.Errorf("invalid resource pattern %q: %w", pattern, err)

0 commit comments

Comments
 (0)