mirror of
https://github.com/kemko/nomad.git
synced 2026-01-10 12:25:42 +03:00
Added a test for file rotation
This commit is contained in:
@@ -24,7 +24,7 @@ func NewLogRotor(path string, fileName string, maxFiles int, fileSize int64) (*L
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logFileIdx := 0
|
||||
logFileIdx := 1
|
||||
for _, f := range files {
|
||||
if strings.HasPrefix(f.Name(), fileName) {
|
||||
fileIdx := strings.TrimPrefix(f.Name(), fmt.Sprintf("%s.", fileName))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package driver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -19,6 +20,7 @@ func TestLogRotator_FindCorrectIndex(t *testing.T) {
|
||||
if err := os.Mkdir(path, os.ModeDir|os.ModePerm); err != nil {
|
||||
t.Fatalf("test setup err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
fname := filepath.Join(path, "redis.stdout.1")
|
||||
if f, err := os.Create(fname); err == nil {
|
||||
@@ -38,3 +40,24 @@ func TestLogRotator_FindCorrectIndex(t *testing.T) {
|
||||
t.Fatalf("Expected log file idx: %v, actual: %v", 2, r.logFileIdx)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogRotator_AppendToCurrentFile(t *testing.T) {
|
||||
path := "/tmp/tmplogrator"
|
||||
if err := os.Mkdir(path, os.ModeDir|os.ModePerm); err != nil {
|
||||
t.Fatalf("test setup err: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(path)
|
||||
fname := filepath.Join(path, "redis.stdout.1")
|
||||
if f, err := os.Create(fname); err == nil {
|
||||
f.Close()
|
||||
}
|
||||
|
||||
r, err := NewLogRotor(path, "redis.stdout", 10, 10)
|
||||
if err != nil {
|
||||
t.Fatalf("test setup err: %v", err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("hello")
|
||||
r.Start(&buf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user