MCPcopy Index your code
hub / github.com/php/frankenphp / TestModuleWorkersDifferentNamesSucceed

Function TestModuleWorkersDifferentNamesSucceed

caddy/config_test.go:64–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestModuleWorkersDifferentNamesSucceed(t *testing.T) {
65 // Create a test configuration with a worker name
66 configWithWorkerName1 := `
67 {
68 php_server {
69 worker {
70 name test-worker-1
71 file ../testdata/worker-with-env.php
72 num 1
73 }
74 }
75 }`
76
77 // Parse the first configuration
78 d1 := caddyfile.NewTestDispenser(configWithWorkerName1)
79 app := &FrankenPHPApp{}
80 module1 := &FrankenPHPModule{}
81
82 // Unmarshal the first configuration
83 err := module1.UnmarshalCaddyfile(d1)
84 require.NoError(t, err, "First module should be configured without errors")
85
86 // Create a second test configuration with a different worker name
87 configWithWorkerName2 := `
88 {
89 php_server {
90 worker {
91 name test-worker-2
92 file ../testdata/worker-with-env.php
93 num 1
94 }
95 }
96 }`
97
98 // Parse the second configuration
99 d2 := caddyfile.NewTestDispenser(configWithWorkerName2)
100 module2 := &FrankenPHPModule{}
101
102 // Unmarshal the second configuration
103 err = module2.UnmarshalCaddyfile(d2)
104
105 // Verify that no error was returned
106 require.NoError(t, err, "Expected no error when two workers have different names")
107
108 _, err = app.addModuleWorkers(module1.Workers...)
109 require.NoError(t, err, "Expected no error when adding the first module workers")
110 _, err = app.addModuleWorkers(module2.Workers...)
111 require.NoError(t, err, "Expected no error when adding the second module workers")
112
113 // Verify that both workers were added
114 require.Len(t, app.Workers, 2, "Expected two workers in the app")
115 require.Equal(t, "m#test-worker-1", app.Workers[0].Name, "First worker should have the correct name")
116 require.Equal(t, "m#test-worker-2", app.Workers[1].Name, "Second worker should have the correct name")
117}
118
119func TestModuleWorkerWithEnvironmentVariables(t *testing.T) {
120 // Create a test configuration with environment variables

Callers

nothing calls this directly

Calls 2

UnmarshalCaddyfileMethod · 0.95
addModuleWorkersMethod · 0.95

Tested by

no test coverage detected