Fixed tests

This commit is contained in:
Diptanu Choudhury 2016-02-19 15:15:59 -08:00
parent 694cecfbf8
commit 0cc9b76d26
2 changed files with 6 additions and 4 deletions

View File

@ -40,7 +40,7 @@ type FileRotator struct {
currentWr int64 currentWr int64
logger *log.Logger logger *log.Logger
purgeCh chan interface{} purgeCh chan struct{}
} }
// NewFileRotator returns a new file rotator // NewFileRotator returns a new file rotator
@ -54,7 +54,7 @@ func NewFileRotator(path string, baseFile string, maxFiles int,
baseFileName: baseFile, baseFileName: baseFile,
logger: logger, logger: logger,
purgeCh: make(chan interface{}), purgeCh: make(chan struct{}, 1),
} }
if err := rotator.lastFile(); err != nil { if err := rotator.lastFile(); err != nil {
return nil, err return nil, err
@ -128,7 +128,7 @@ func (f *FileRotator) nextFile() error {
// Purge old files if we have more files than MaxFiles // Purge old files if we have more files than MaxFiles
if f.logFileIdx-f.oldestLogFileIdx >= f.MaxFiles { if f.logFileIdx-f.oldestLogFileIdx >= f.MaxFiles {
select { select {
case f.purgeCh <- new(interface{}): case f.purgeCh <- struct{}{}:
default: default:
} }
} }

View File

@ -3,13 +3,15 @@
package logging package logging
import ( import (
"log"
"log/syslog" "log/syslog"
"os"
"testing" "testing"
) )
func TestLogParser_Priority(t *testing.T) { func TestLogParser_Priority(t *testing.T) {
line := []byte("<30>2016-02-10T10:16:43-08:00 d-thinkpad docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf") line := []byte("<30>2016-02-10T10:16:43-08:00 d-thinkpad docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf")
d := NewDockerLogParser(line) d := NewDockerLogParser(log.New(os.Stdout, "", log.LstdFlags))
p, _, err := d.parsePriority(line) p, _, err := d.parsePriority(line)
if err != nil { if err != nil {
t.Fatalf("got an err: %v", err) t.Fatalf("got an err: %v", err)