|
| 1 | +//go:build fsnotify |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright 2020 Docker Compose CLI authors |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package watch |
| 20 | + |
| 21 | +import ( |
| 22 | + "testing" |
| 23 | + |
| 24 | + "gotest.tools/v3/assert" |
| 25 | +) |
| 26 | + |
| 27 | +func TestFseventNotifyCloseIdempotent(t *testing.T) { |
| 28 | + // Create a watcher with a temporary directory |
| 29 | + tmpDir := t.TempDir() |
| 30 | + watcher, err := newWatcher([]string{tmpDir}) |
| 31 | + assert.NilError(t, err) |
| 32 | + |
| 33 | + // Start the watcher |
| 34 | + err = watcher.Start() |
| 35 | + assert.NilError(t, err) |
| 36 | + |
| 37 | + // Close should work the first time |
| 38 | + err = watcher.Close() |
| 39 | + assert.NilError(t, err) |
| 40 | + |
| 41 | + // Close should be idempotent - calling it again should not panic |
| 42 | + err = watcher.Close() |
| 43 | + assert.NilError(t, err) |
| 44 | + |
| 45 | + // Even a third time should be safe |
| 46 | + err = watcher.Close() |
| 47 | + assert.NilError(t, err) |
| 48 | +} |
0 commit comments