mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
use 🧩 for module workers
This commit is contained in:
@@ -49,7 +49,7 @@ func init() {
|
||||
}
|
||||
|
||||
type workerConfig struct {
|
||||
// Name for the worker. Default: the filename for FrankenPHPApp workers, always prefixed with "m#" for FrankenPHPModule workers.
|
||||
// Name for the worker. Default: the filename for FrankenPHPApp workers, always prefixed with "🧩 " for FrankenPHPModule workers.
|
||||
Name string `json:"name,omitempty"`
|
||||
// FileName sets the path to the worker script.
|
||||
FileName string `json:"file_name,omitempty"`
|
||||
@@ -318,8 +318,8 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
}
|
||||
wc.Name = name
|
||||
}
|
||||
if strings.HasPrefix(wc.Name, "m#") {
|
||||
return fmt.Errorf("global worker names must not start with 'm#': %q", wc.Name)
|
||||
if strings.HasPrefix(wc.Name, "🧩 ") {
|
||||
return fmt.Errorf("global worker names must not start with '🧩 ': %q", wc.Name)
|
||||
}
|
||||
// check for duplicate workers
|
||||
for _, existingWorker := range f.Workers {
|
||||
@@ -499,7 +499,7 @@ func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ c
|
||||
}
|
||||
|
||||
func generateUniqueModuleWorkerName(filepath string) string {
|
||||
name := "m#" + filepath
|
||||
name := "🧩 " + filepath
|
||||
i := 0
|
||||
for {
|
||||
nameExists := false
|
||||
@@ -513,7 +513,7 @@ func generateUniqueModuleWorkerName(filepath string) string {
|
||||
break
|
||||
}
|
||||
i++
|
||||
name = fmt.Sprintf("m#%s_%d", filepath, i)
|
||||
name = fmt.Sprintf("🧩 %s_%d", filepath, i)
|
||||
}
|
||||
|
||||
return name
|
||||
@@ -607,8 +607,8 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
if wc.Name == "" {
|
||||
wc.Name = generateUniqueModuleWorkerName(wc.FileName)
|
||||
}
|
||||
if !strings.HasPrefix(wc.Name, "m#") {
|
||||
wc.Name = "m#" + wc.Name
|
||||
if !strings.HasPrefix(wc.Name, "🧩 ") {
|
||||
wc.Name = "🧩 " + wc.Name
|
||||
}
|
||||
|
||||
// Check if a worker with this filename already exists in this module
|
||||
|
||||
@@ -160,8 +160,8 @@ func TestModuleWorkersDifferentNamesSucceed(t *testing.T) {
|
||||
|
||||
// Verify that both workers were added to moduleWorkerConfigs
|
||||
require.Len(t, moduleWorkerConfigs, 2, "Expected two workers to be added to moduleWorkerConfigs")
|
||||
require.Equal(t, "m#test-worker-1", moduleWorkerConfigs[0].Name, "First worker should have the correct name")
|
||||
require.Equal(t, "m#test-worker-2", moduleWorkerConfigs[1].Name, "Second worker should have the correct name")
|
||||
require.Equal(t, "🧩 test-worker-1", moduleWorkerConfigs[0].Name, "First worker should have the correct name")
|
||||
require.Equal(t, "🧩 test-worker-2", moduleWorkerConfigs[1].Name, "Second worker should have the correct name")
|
||||
|
||||
resetModuleWorkers()
|
||||
}
|
||||
@@ -267,8 +267,8 @@ func TestModuleWorkerWithCustomName(t *testing.T) {
|
||||
require.Len(t, module.Workers, 1, "Expected one worker to be added to the module")
|
||||
require.Equal(t, "../testdata/worker-with-env.php", module.Workers[0].FileName, "Worker should have the correct filename")
|
||||
|
||||
// Verify that the worker was added to moduleWorkerConfigs with the m# prefix
|
||||
require.Equal(t, "m#custom-worker-name", module.Workers[0].Name, "Worker should have the custom name")
|
||||
// Verify that the worker was added to moduleWorkerConfigs with the 🧩 prefix
|
||||
require.Equal(t, "🧩 custom-worker-name", module.Workers[0].Name, "Worker should have the custom name")
|
||||
|
||||
resetModuleWorkers()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user