Skip to content

Commit 9a875fa

Browse files
committed
test: add watch pattern exclusion test for Caddy configuration
Add test case for worker watch configuration with exclude patterns. Verifies that exclude patterns (prefixed with !) are correctly parsed and stored alongside include patterns in the watch configuration.
1 parent 6a2b778 commit 9a875fa

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

caddy/config_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,39 @@ func TestModuleWorkerWithCustomName(t *testing.T) {
220220
require.Equal(t, "m#custom-worker-name", module.Workers[0].Name, "Worker should have the custom name, prefixed with m#")
221221
require.Equal(t, "m#custom-worker-name", app.Workers[0].Name, "Worker should have the custom name, prefixed with m#")
222222
}
223+
224+
func TestWorkerWatchAllowsExcludePatterns(t *testing.T) {
225+
// Create a test configuration with an exclude watch pattern
226+
configWithExcludeWatch := `
227+
{
228+
php {
229+
worker {
230+
file ../testdata/worker-with-env.php
231+
num 1
232+
watch
233+
watch !./vendor/**
234+
watch ./src/**/*.php
235+
}
236+
}
237+
}`
238+
239+
// Parse the configuration
240+
d := caddyfile.NewTestDispenser(configWithExcludeWatch)
241+
module := &FrankenPHPModule{}
242+
243+
// Unmarshal the configuration
244+
err := module.UnmarshalCaddyfile(d)
245+
246+
// Verify that no error was returned
247+
require.NoError(t, err, "Expected no error when configuring a worker with an exclude watch pattern")
248+
249+
// Verify that the worker was added to the module
250+
require.Len(t, module.Workers, 1, "Expected one worker to be added to the module")
251+
require.Equal(t, "../testdata/worker-with-env.php", module.Workers[0].FileName, "Worker should have the correct filename")
252+
253+
// Verify that the watch patterns were set correctly
254+
require.Len(t, module.Workers[0].Watch, 3, "Expected three watch patterns")
255+
require.Equal(t, defaultWatchPattern, module.Workers[0].Watch[0], "First watch pattern should be the default")
256+
require.Equal(t, "!./vendor/**", module.Workers[0].Watch[1], "Second watch pattern should be the exclude pattern")
257+
require.Equal(t, "./src/**/*.php", module.Workers[0].Watch[2], "Third watch pattern should match the configuration")
258+
}

0 commit comments

Comments
 (0)