test(action): add test for writeToFile trailing newline fix

Verify that output files written via --output-dir end with exactly one
newline and not two, covering the regression fixed in #32163.

Co-authored-by: Cloud-Architect-Emma <Cloud-Architect-Emma@users.noreply.github.com>
Signed-off-by: Cloud-Architect-Emma <your@email.com>
pull/32170/head
Cloud-Architect-Emma 2 weeks ago
parent 62eb653164
commit ff18e5b0ef

@ -1297,3 +1297,35 @@ func TestInstallRelease_WaitOptionsPassedDownstream(t *testing.T) {
// Verify that WaitOptions were passed to GetWaiter
is.NotEmpty(failer.RecordedWaitOptions, "WaitOptions should be passed to GetWaiter")
}
func TestWriteToFileNoTrailingNewline(t *testing.T) {
is := assert.New(t)
instAction := installAction(t)
vals := map[string]any{}
dir := t.TempDir()
instAction.OutputDir = dir
_, err := instAction.Run(buildChart(withSampleTemplates()), vals)
if err != nil {
t.Fatalf("Failed install: %s", err)
}
// Each output file should end with exactly one newline, not two.
for _, name := range []string{
"hello/templates/hello",
"hello/templates/goodbye",
} {
path := filepath.Join(dir, name)
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Failed to read %s: %s", path, err)
}
is.True(len(data) > 0, "file should not be empty: %s", name)
is.Equal(byte('\n'), data[len(data)-1], "file should end with exactly one newline: %s", name)
if len(data) >= 2 {
is.NotEqual(byte('\n'), data[len(data)-2], "file should not end with two newlines: %s", name)
}
}
}
Loading…
Cancel
Save