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 4 months ago
parent d35c8eeb99
commit f21f0c1358

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