Skip to content

Commit

Permalink
watch: add note about goroutine-safety & test
Browse files Browse the repository at this point in the history
Signed-off-by: Milas Bowman <[email protected]>
  • Loading branch information
milas committed Mar 23, 2023
1 parent 7aaea28 commit 16d5354
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/watch/ephemeral.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ package watch
// stop-gap so they don't have a terrible experience if those files aren't
// there or aren't in the right places.
//
// https://app.clubhouse.io/windmill/story/691/filter-out-ephemeral-file-changes
// NOTE: The underlying `patternmatcher` is NOT always Goroutine-safe, so
// this is not a singleton; we create an instance for each watcher currently.
func EphemeralPathMatcher() PathMatcher {
golandPatterns := []string{"**/*___jb_old___", "**/*___jb_tmp___", "**/.idea/**"}
emacsPatterns := []string{"**/.#*", "**/#*#"}
Expand Down
49 changes: 49 additions & 0 deletions pkg/watch/ephemeral_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2023 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package watch_test

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/docker/compose/v2/pkg/watch"
)

func TestEphemeralPathMatcher(t *testing.T) {
ignored := []string{
".file.txt.swp",
"/path/file.txt~",
"/home/moby/proj/.idea/modules.xml",
".#file.txt",
"#file.txt#",
"/dir/.file.txt.kate-swp",
"/go/app/1234-go-tmp-umask",
}
matcher := watch.EphemeralPathMatcher()
for _, p := range ignored {
ok, err := matcher.Matches(p)
if assert.NoErrorf(t, err, "Matching %s", p) {
assert.Truef(t, ok, "Path %s should have matched", p)
}
}

const includedPath = "normal.txt"
ok, err := matcher.Matches(includedPath)
if assert.NoErrorf(t, err, "Matching %s", includedPath) {
assert.Falsef(t, ok, "Path %s should NOT have matched", includedPath)
}
}

0 comments on commit 16d5354

Please sign in to comment.