|
| 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