Skip to content

Commit 16d5354

Browse files
committed
watch: add note about goroutine-safety & test
Signed-off-by: Milas Bowman <[email protected]>
1 parent 7aaea28 commit 16d5354

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

pkg/watch/ephemeral.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ package watch
2424
// stop-gap so they don't have a terrible experience if those files aren't
2525
// there or aren't in the right places.
2626
//
27-
// https://app.clubhouse.io/windmill/story/691/filter-out-ephemeral-file-changes
27+
// NOTE: The underlying `patternmatcher` is NOT always Goroutine-safe, so
28+
// this is not a singleton; we create an instance for each watcher currently.
2829
func EphemeralPathMatcher() PathMatcher {
2930
golandPatterns := []string{"**/*___jb_old___", "**/*___jb_tmp___", "**/.idea/**"}
3031
emacsPatterns := []string{"**/.#*", "**/#*#"}

pkg/watch/ephemeral_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2023 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package watch_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
23+
"github.com/docker/compose/v2/pkg/watch"
24+
)
25+
26+
func TestEphemeralPathMatcher(t *testing.T) {
27+
ignored := []string{
28+
".file.txt.swp",
29+
"/path/file.txt~",
30+
"/home/moby/proj/.idea/modules.xml",
31+
".#file.txt",
32+
"#file.txt#",
33+
"/dir/.file.txt.kate-swp",
34+
"/go/app/1234-go-tmp-umask",
35+
}
36+
matcher := watch.EphemeralPathMatcher()
37+
for _, p := range ignored {
38+
ok, err := matcher.Matches(p)
39+
if assert.NoErrorf(t, err, "Matching %s", p) {
40+
assert.Truef(t, ok, "Path %s should have matched", p)
41+
}
42+
}
43+
44+
const includedPath = "normal.txt"
45+
ok, err := matcher.Matches(includedPath)
46+
if assert.NoErrorf(t, err, "Matching %s", includedPath) {
47+
assert.Falsef(t, ok, "Path %s should NOT have matched", includedPath)
48+
}
49+
}

0 commit comments

Comments
 (0)