test(action): simplify trailing newline assertion

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 3 days ago
parent d35c8eeb99
commit f21f0c1358

@ -1299,7 +1299,6 @@ func TestInstallRelease_WaitOptionsPassedDownstream(t *testing.T) {
}
func TestWriteToFileNoTrailingNewline(t *testing.T) {
is := assert.New(t)
instAction := installAction(t)
vals := map[string]any{}
@ -1311,7 +1310,7 @@ func TestWriteToFileNoTrailingNewline(t *testing.T) {
t.Fatalf("Failed install: %s", err)
}
// Each output file should end with exactly one newline, not two.
// Each output file should end with exactly one newline (no double newline).
for _, name := range []string{
"hello/templates/hello",
"hello/templates/goodbye",
@ -1321,10 +1320,12 @@ func TestWriteToFileNoTrailingNewline(t *testing.T) {
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)
content := string(data)
if strings.HasSuffix(content, "\n\n") {
t.Errorf("file %s ends with double newline, expected single newline", name)
}
if !strings.HasSuffix(content, "\n") {
t.Errorf("file %s does not end with a newline", name)
}
}
}
}
Loading…
Cancel
Save