Skip to content

Commit

Permalink
#5 debug windows file tailer test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Jan 31, 2019
1 parent 5ac936c commit 386f890
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tailer/fileTailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ func rotate(t *testing.T, log logrus.FieldLogger, logfile string, opt logrotateO
}
switch {
case opt == _nocreate:
moveOrFail(t, mvOpt, logfile)
moveOrFail(t, mvOpt, logfile, log)
case opt == _create:
moveOrFail(t, mvOpt, logfile)
moveOrFail(t, mvOpt, logfile, log)
createOrFail(t, logfile)
case opt == _create_from_temp:
moveOrFail(t, mvOpt, logfile)
moveOrFail(t, mvOpt, logfile, log)
createFromTemp(t, logfile)
case opt == _copytruncate:
if mvOpt != cp {
Expand All @@ -493,24 +493,42 @@ func rotate(t *testing.T, log logrus.FieldLogger, logfile string, opt logrotateO
log.Debugf("Simulated logrotate with option %v and mvOption %v\n", opt, mvOpt)
}

func moveOrFail(t *testing.T, mvOpt logrotateMoveOption, logfile string) {
func moveOrFail(t *testing.T, mvOpt logrotateMoveOption, logfile string, log logrus.FieldLogger) {
dir := filepath.Dir(logfile)
filename := filepath.Base(logfile)
switch {
case mvOpt == mv:
log.Debugf("file list before: %#v", filenames(ls(t, dir)))
log.Debugf("mv %v %v", logfile, fmt.Sprintf("%v.1", logfile))
mvOrFail(t, logfile, fmt.Sprintf("%v.1", logfile))
log.Debugf("file list after: %#v", filenames(ls(t, dir)))
case mvOpt == cp:
log.Debugf("file list before: %#v", filenames(ls(t, dir)))
log.Debugf("cp %v %v", logfile, fmt.Sprintf("%v.1", logfile))
log.Debugf("rm %v", fmt.Sprintf("%v.1", logfile))
cpOrFail(t, logfile, fmt.Sprintf("%v.1", logfile))
rmOrFail(t, logfile)
log.Debugf("file list after: %#v", filenames(ls(t, dir)))
case mvOpt == rm:
log.Debugf("file list before: %#v", filenames(ls(t, dir)))
log.Debugf("rm %v", logfile)
rmOrFail(t, logfile)
log.Debugf("file list after: %#v", filenames(ls(t, dir)))
}
filesAfterRename := ls(t, dir)
if containsFile(filesAfterRename, filename) {
t.Fatalf("%v still contains file %v after mv.", dir, filename)
}
}

func filenames(fileInfos []os.FileInfo) []string {
result := make([]string, 0, len(fileInfos))
for _, fileInfo := range fileInfos {
result = append(result, fileInfo.Name())
}
return result
}

func mvOrFail(t *testing.T, fromPath string, toPath string) {
err := os.Rename(fromPath, toPath)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions tailer/fswatcher/fswatcher_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func (w *watcher) syncFilesInDir(dirPath string, readall bool, log logrus.FieldL
return nil
}

// TODO: Replace with ioutil.Readdir
func ls(dirPath string) ([]os.FileInfo, Error) {
var (
dir *os.File
Expand Down

0 comments on commit 386f890

Please sign in to comment.