@@ -14,14 +14,17 @@ import (
14
14
"github.com/Skarlso/crd-to-sample-yaml/pkg/tests"
15
15
)
16
16
17
+ // MatcherName is the name of this matcher YAML.
17
18
const MatcherName = "matchSnapshot"
18
19
20
+ // Config contains configuration details for the Matcher. Path, ignoring errors and minimal setting.
19
21
type Config struct {
20
22
Path string `yaml:"path"`
21
23
IgnoreErrors []string `yaml:"ignoreErrors,omitempty"`
22
24
Minimal bool `yaml:"minimal"`
23
25
}
24
26
27
+ // Matcher is a snapshot based matcher.
25
28
type Matcher struct {
26
29
Updater Updater
27
30
}
@@ -32,6 +35,7 @@ func init() {
32
35
}, MatcherName )
33
36
}
34
37
38
+ // Match actually does the matching.
35
39
func (m * Matcher ) Match (ctx context.Context , crdLocation string , payload []byte ) error {
36
40
c := Config {}
37
41
if err := yaml .Unmarshal (payload , & c ); err != nil {
@@ -79,7 +83,7 @@ func (m *Matcher) Match(ctx context.Context, crdLocation string, payload []byte)
79
83
return err
80
84
}
81
85
82
- content , err := os .ReadFile (crdLocation )
86
+ content , err := os .ReadFile (filepath . Clean ( crdLocation ) )
83
87
if err != nil {
84
88
return fmt .Errorf ("failed to read source template: %w" , err )
85
89
}
@@ -89,7 +93,7 @@ func (m *Matcher) Match(ctx context.Context, crdLocation string, payload []byte)
89
93
for _ , s := range snapshots {
90
94
// one snapshot will contain a single version and the validation
91
95
// will know which version to check against
92
- snapshotContent , err := os .ReadFile (s )
96
+ snapshotContent , err := os .ReadFile (filepath . Clean ( s ) )
93
97
if err != nil {
94
98
return fmt .Errorf ("failed to read snapshot template: %w" , err )
95
99
}
0 commit comments