From 80ac8c2a37ee0857fa410b61763e0ac4f52a7f05 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Fri, 11 May 2018 10:52:09 -0700 Subject: [PATCH] Add new line test --- client/driver/logging/rotator_test.go | 31 +++++++++++---------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/client/driver/logging/rotator_test.go b/client/driver/logging/rotator_test.go index 7eaf4188719..4fcf23952a0 100644 --- a/client/driver/logging/rotator_test.go +++ b/client/driver/logging/rotator_test.go @@ -183,34 +183,27 @@ func TestFileRotator_RotateFiles_Boundary(t *testing.T) { t.Fatalf("test setup err: %v", err) } - // We will write two times: + // We will write three times: // 1st: Write with new lines spanning two files // 2nd: Write long string with no new lines + // 3rd: Write a single new line expectations := [][]byte{ []byte("ab\n"), []byte("cdef\n"), []byte("12345"), - []byte("6789"), + []byte("67890"), + []byte("\n"), } - str1 := "ab\ncdef\n" - str2 := "123456789" - nw, err := fr.Write([]byte(str1)) - if err != nil { - t.Fatalf("got error while writing: %v", err) - } - - if nw != len(str1) { - t.Fatalf("expected %v, got %v", len(str1), nw) - } - - nw, err = fr.Write([]byte(str2)) - if err != nil { - t.Fatalf("got error while writing: %v", err) - } + for _, str := range []string{"ab\ncdef\n", "1234567890", "\n"} { + nw, err := fr.Write([]byte(str)) + if err != nil { + t.Fatalf("got error while writing: %v", err) + } - if nw != len(str2) { - t.Fatalf("expected %v, got %v", len(str2), nw) + if nw != len(str) { + t.Fatalf("expected %v, got %v", len(str), nw) + } } var lastErr error