Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve watcher logging #80

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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