Skip to content

Commit

Permalink
fix Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Feb 14, 2020
1 parent 1e83c8d commit dda32d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
6 changes: 3 additions & 3 deletions config/v3/fileLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"github.com/fstab/grok_exporter/tailer/glob"
"io/ioutil"
"path"
"path/filepath"
)

type ConfigFile struct {
Expand All @@ -38,7 +38,7 @@ func NewFileLoader() FileLoader {
}

func (f *fileLoader) LoadDir(dir string) ([]*ConfigFile, error) {
return f.LoadGlob(path.Join(dir, "*"))
return f.LoadGlob(filepath.Join(dir, "*"))
}

func (f *fileLoader) LoadGlob(globString string) ([]*ConfigFile, error) {
Expand All @@ -52,7 +52,7 @@ func (f *fileLoader) LoadGlob(globString string) ([]*ConfigFile, error) {
return nil, err
}
for _, fileInfo := range fileInfos {
filePath := path.Join(g.Dir(), fileInfo.Name())
filePath := filepath.Join(g.Dir(), fileInfo.Name())
if g.Match(filePath) {
contents, err := ioutil.ReadFile(filePath)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions config/v3/fileLoader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package v3
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -97,11 +96,11 @@ func setUp(t *testing.T) string {
if err != nil {
t.Fatalf("failed to create test directory: %v", err)
}
err = ioutil.WriteFile(path.Join(dir, "file1.yaml"), []byte(file1Contents), 0644)
err = ioutil.WriteFile(filepath.Join(dir, "file1.yaml"), []byte(file1Contents), 0644)
if err != nil {
t.Fatalf("unexpected error writing file1.yaml: %v", err)
}
err = ioutil.WriteFile(path.Join(dir, "file2.yaml"), []byte(file2Contents), 0644)
err = ioutil.WriteFile(filepath.Join(dir, "file2.yaml"), []byte(file2Contents), 0644)
if err != nil {
t.Fatalf("unexpected error writing file2.yaml: %v", err)
}
Expand Down
29 changes: 14 additions & 15 deletions tailer/fswatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io/ioutil"
"os"
"os/user"
"path"
"path/filepath"
"runtime"
"runtime/pprof"
Expand Down Expand Up @@ -384,7 +383,7 @@ func exec(t *testing.T, ctx *context, cmd []string) {
case "log":
writer, exists := ctx.logFileWriters[cmd[2]]
if !exists {
writer = newLogFileWriter(t, ctx, path.Join(ctx.basedir, cmd[2]))
writer = newLogFileWriter(t, ctx, filepath.Join(ctx.basedir, cmd[2]))
ctx.logFileWriters[cmd[2]] = writer
}
writer.writeLine(t, ctx, cmd[1])
Expand All @@ -406,7 +405,7 @@ func exec(t *testing.T, ctx *context, cmd []string) {
}

func rotate(t *testing.T, ctx *context, from string, to string) {
fullpath := path.Join(ctx.basedir, from)
fullpath := filepath.Join(ctx.basedir, from)
fromDir := filepath.Dir(fullpath)
filenameFrom := filepath.Base(fullpath)
filesBefore := ls(t, ctx, fromDir)
Expand Down Expand Up @@ -463,7 +462,7 @@ func containsFile(files []os.FileInfo, filename string) bool {
}

func moveOrFail(t *testing.T, ctx *context, from, to string) {
fromPath := path.Join(ctx.basedir, from)
fromPath := filepath.Join(ctx.basedir, from)
fromDir := filepath.Dir(fromPath)
fromFilename := filepath.Base(fromPath)
switch {
Expand Down Expand Up @@ -494,17 +493,17 @@ func filenames(fileInfos []os.FileInfo) []string {
}

func mvOrFail(t *testing.T, ctx *context, from, to string) {
fromPath := path.Join(ctx.basedir, from)
toPath := path.Join(ctx.basedir, to)
fromPath := filepath.Join(ctx.basedir, from)
toPath := filepath.Join(ctx.basedir, to)
err := os.Rename(fromPath, toPath)
if err != nil {
fatalf(t, ctx, "%v: Failed to mv file: %v", fromPath, err.Error())
}
}

func cpOrFail(t *testing.T, ctx *context, from, to string) {
fromPath := path.Join(ctx.basedir, from)
toPath := path.Join(ctx.basedir, to)
fromPath := filepath.Join(ctx.basedir, from)
toPath := filepath.Join(ctx.basedir, to)
data, err := ioutil.ReadFile(fromPath)
if err != nil {
fatalf(t, ctx, "%v: Copy failed, cannot read file: %v", fromPath, err.Error())
Expand All @@ -516,15 +515,15 @@ func cpOrFail(t *testing.T, ctx *context, from, to string) {
}

func rmOrFail(t *testing.T, ctx *context, from string) {
fromPath := path.Join(ctx.basedir, from)
fromPath := filepath.Join(ctx.basedir, from)
err := os.Remove(fromPath)
if err != nil {
fatalf(t, ctx, "%v: Remove failed: %v", fromPath, err.Error())
}
}

func createOrFail(t *testing.T, ctx *context, from string) {
fromPath := path.Join(ctx.basedir, from)
fromPath := filepath.Join(ctx.basedir, from)
dir := filepath.Dir(fromPath)
filename := filepath.Base(fromPath)
filesBeforeCreate := ls(t, ctx, dir)
Expand All @@ -546,7 +545,7 @@ func createOrFail(t *testing.T, ctx *context, from string) {
}

func createFromTemp(t *testing.T, ctx *context, from string) {
fromPath := path.Join(ctx.basedir, from)
fromPath := filepath.Join(ctx.basedir, from)
dir := filepath.Dir(fromPath)
filename := filepath.Base(fromPath)
filesBeforeCreate := ls(t, ctx, dir)
Expand All @@ -573,7 +572,7 @@ func createFromTemp(t *testing.T, ctx *context, from string) {
}

func truncateOrFail(t *testing.T, ctx *context, from string) {
fromPath := path.Join(ctx.basedir, from)
fromPath := filepath.Join(ctx.basedir, from)
err := os.Truncate(fromPath, 0)
if err != nil {
fatalf(t, ctx, "%v: Error truncating the file: %v", from, err.Error())
Expand All @@ -585,7 +584,7 @@ func mkdir(t *testing.T, ctx *context, dirname string) {
fullpath string
err error
)
fullpath = path.Join(ctx.basedir, dirname)
fullpath = filepath.Join(ctx.basedir, dirname)
if _, err = os.Stat(fullpath); !os.IsNotExist(err) {
fatalf(t, ctx, "mkdir %v failed: directory already exists", dirname)
}
Expand Down Expand Up @@ -845,7 +844,7 @@ func deleteRecursively(t *testing.T, ctx *context, file string) {
}
if fileInfo.IsDir() {
for _, childInfo := range ls(t, ctx, file) {
deleteRecursively(t, ctx, path.Join(file, childInfo.Name()))
deleteRecursively(t, ctx, filepath.Join(file, childInfo.Name()))
}
}
ctx.log.Debugf("tearDown: removing %q", file)
Expand Down Expand Up @@ -938,7 +937,7 @@ func runTestShutdown(t *testing.T, mode string) {
nGoroutinesBefore := runtime.NumGoroutine()

ctx := setUp(t, "test shutdown while "+mode, closeFileAfterEachLine, fseventTailer, _nocreate, mv)
writer := newLogFileWriter(t, ctx, path.Join(ctx.basedir, "test.log"))
writer := newLogFileWriter(t, ctx, filepath.Join(ctx.basedir, "test.log"))
writer.writeLine(t, ctx, "line 1")

parsedGlob, err := glob.Parse(filepath.Join(ctx.basedir, "test.log"))
Expand Down

0 comments on commit dda32d7

Please sign in to comment.