Skip to content

Commit

Permalink
Merge pull request #80 from yowcow/improve-watcher-logging
Browse files Browse the repository at this point in the history
Improve watcher logging
  • Loading branch information
yowcow authored Jul 11, 2018
2 parents 710e20a + d05d506 commit 881c6e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (w Watcher) watch(ctx context.Context, out chan<- string) {
os.Remove(w.md5file)
out <- w.File
} else if err != nil {
w.logger.Println("watcher file verification failed ", err.Error())
w.logger.Println("watcher file verification failed:", err.Error())
}
case <-ctx.Done():
return
Expand All @@ -64,7 +64,7 @@ func verifyFile(file, md5file string) (bool, error) {

md5fi, err := os.Open(md5file)
if err != nil {
return false, nil
return false, fmt.Errorf("file %s is found but %s is not found", file, md5file)
}
defer md5fi.Close()

Expand Down
6 changes: 3 additions & 3 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestVerifyFile(t *testing.T) {
}
cases := []Case{
{"non-existing.txt", "non-existing.txt.md5", false, false, "non-existing file"},
{"valid.txt", "non-existing.txt.md5", false, false, "non-existing md5 file"},
{"valid.txt", "non-existing.txt.md5", false, true, "non-existing md5 file"},
{"valid.txt", "invalid-len.txt.md5", false, true, "invalid md5 length"},
{"valid.txt", "invalid-sum.txt.md5", false, true, "invalid md5 sum"},
{"valid.txt", "valid.txt.md5", true, false, "valid md5"},
Expand Down Expand Up @@ -63,8 +63,8 @@ func TestStart(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*100)
out := wcr.Start(ctx)
<-out
cancel()
<-out // out should get closed after cancel() call
}

func TestWatchOutput(t *testing.T) {
Expand All @@ -85,7 +85,7 @@ func TestWatchOutput(t *testing.T) {

loadedFile := <-out
cancel()
<-out
<-out // out should get closed after cancel() call

assert.Equal(t, file, loadedFile)

Expand Down

0 comments on commit 881c6e0

Please sign in to comment.