Skip to content

Commit

Permalink
fix: apply suggestion
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Jul 9, 2020
1 parent 8ee9d3c commit 5962d6b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/file/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func (w *watch) init() (*watch, error) {
return nil, err
}
w.mu.RLock()
dirs := w.dirs
dirs := make(map[string]struct{}, len(w.dirs))
for name, val := range w.dirs {
dirs[name] = val
}
w.mu.RUnlock()
for dir := range dirs {
log.Debug("Adding watcher target: ", dir)
Expand Down
30 changes: 30 additions & 0 deletions internal/file/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ func Test_watch_init(t *testing.T) {
},
},

{
name: "returns nil when watcher already created and initialize success",
fields: fields{
dirs: map[string]struct{}{
"../watch": struct{}{},
"watch.go": struct{}{},
"watch_test.go": struct{}{},
},
w: func() *fsnotify.Watcher {
w, _ := fsnotify.NewWatcher()
return w
}(),
},
checkFunc: func(w want, got *watch, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got error = %v, want %v", err, w.err)
}
if got == nil {
return errors.New("got is nil")
}
if got.w == nil {
return errors.New("got w is nil")
}
return nil
},
want: want{
err: nil,
},
},

{
name: "returns nil when initialize success",
fields: fields{
Expand Down

0 comments on commit 5962d6b

Please sign in to comment.