From 2c49556b2eedfe959202659ae56f0fdf04207f42 Mon Sep 17 00:00:00 2001 From: Marc Lallaouret Date: Thu, 16 Jun 2016 18:33:55 +0200 Subject: [PATCH] Clean current output file name (#304) --- output_file.go | 4 ++-- output_file_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/output_file.go b/output_file.go index 4c863fcdc..044068d3a 100644 --- a/output_file.go +++ b/output_file.go @@ -11,8 +11,8 @@ import ( "sort" "strconv" "strings" - "time" "sync" + "time" ) var dateFileNameFuncs = map[string]func() string{ @@ -170,7 +170,7 @@ func (o *FileOutput) filename() string { } func (o *FileOutput) updateName() { - o.currentName = o.filename() + o.currentName = filepath.Clean(o.filename()) } func (o *FileOutput) Write(data []byte) (n int, err error) { diff --git a/output_file_test.go b/output_file_test.go index b086740d1..04601f810 100644 --- a/output_file_test.go +++ b/output_file_test.go @@ -53,6 +53,17 @@ func TestFileOutput(t *testing.T) { close(quit) } +func TestFileOutputWithNameCleaning(t *testing.T) { + output := &FileOutput{pathTemplate: "./test_requests.gor", config: &FileOutputConfig{flushInterval: time.Minute, append: false}} + expectedFileName := "test_requests_0.gor" + output.updateName() + + if expectedFileName != output.currentName { + t.Errorf("Expected path %s but got %s", expectedFileName, output.currentName) + } + +} + func TestFileOutputPathTemplate(t *testing.T) { output := &FileOutput{pathTemplate: "/tmp/log-%Y-%m-%d-%S", config: &FileOutputConfig{flushInterval: time.Minute, append: true}} now := time.Now()