Added a test for testing if logrotator creates an empty dir when it starts from scratch

This commit is contained in:
Diptanu Choudhury 2016-01-14 22:43:52 -08:00
parent 5835d0e436
commit 385fe065ec
1 changed files with 32 additions and 0 deletions

View File

@ -120,3 +120,35 @@ func TestLogRotator_RotateFiles(t *testing.T) {
t.Fatalf("Expected number of files: %v, actual: %v", 2, numFiles)
}
}
func TestLogRotator_StartFromEmptyDir(t *testing.T) {
path := "/tmp/tmplogrator"
defer os.RemoveAll(path)
if err := os.Mkdir(path, os.ModeDir|os.ModePerm); err != nil {
t.Fatalf("test setup err: %v", err)
}
l, err := NewLogRotator(path, "redis.stdout", 10, 10)
if err != nil {
t.Fatalf("test setup err: %v", err)
}
r, w := io.Pipe()
go func() {
w.Write([]byte("abcdefg"))
w.Close()
}()
err = l.Start(r)
if err != nil && err != io.EOF {
t.Fatalf("Failure in logrotator start %v", err)
}
finfo, err := os.Stat(filepath.Join(path, "redis.stdout.0"))
if err != nil {
t.Fatal(err)
}
if finfo.Size() != 7 {
t.Fatalf("expected size of file: %v, actual: %v", 7, finfo.Size())
}
}