mirror of
https://github.com/fluxcd/flux2.git
synced 2026-04-29 22:58:50 +00:00
test: ignore golden template files with -update
Add a template values check in the `assertGoldenTemplateFile()` function to only update golden files if they aren't templates. A note is printed when an update to a template golden file is needed and `-update` flag can't update it. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
parent
edaf6ca522
commit
2c4c3fd749
3 changed files with 24 additions and 5 deletions
|
|
@ -304,10 +304,15 @@ func assertGoldenTemplateFile(goldenFile string, templateValues map[string]strin
|
|||
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
|
||||
// Update the golden files if comparision fails and the update flag is set.
|
||||
if *update && output != "" {
|
||||
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
|
||||
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
|
||||
// Skip update if there are template values.
|
||||
if len(templateValues) > 0 {
|
||||
fmt.Println("NOTE: -update flag passed but golden template files can't be updated, please update it manually")
|
||||
} else {
|
||||
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
|
||||
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue