Skip to content

Commit 2c2f677

Browse files
committed
add caddy/config_tests, add --retry 5 to download
1 parent 5fc1edf commit 2c2f677

3 files changed

Lines changed: 92 additions & 8 deletions

File tree

build-static.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ if [ -z "${SPC_OPT_BUILD_ARGS}" ]; then
4646
fi
4747
# init spc download additional args
4848
if [ -z "${SPC_OPT_DOWNLOAD_ARGS}" ]; then
49+
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src --retry 5"
4950
if [ "${SPC_LIBC}" = "musl" ]; then
50-
SPC_OPT_DOWNLOAD_ARGS="--prefer-pre-built --ignore-cache-sources=php-src"
51-
else
52-
SPC_OPT_DOWNLOAD_ARGS="--ignore-cache-sources=php-src"
51+
SPC_OPT_DOWNLOAD_ARGS="${SPC_OPT_DOWNLOAD_ARGS} --prefer-pre-built"
5352
fi
5453
fi
5554
# if we need debug symbols, disable strip

caddy/config_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package caddy
2+
3+
import (
4+
"testing"
5+
6+
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
// resetModuleWorkers resets the moduleWorkers slice for testing
11+
func resetModuleWorkers() {
12+
moduleWorkers = make([]workerConfig, 0)
13+
}
14+
15+
func TestModuleWorkerDuplicateFilenamesFail(t *testing.T) {
16+
// Create a test configuration with duplicate worker filenames
17+
configWithDuplicateFilenames := `
18+
{
19+
php {
20+
worker {
21+
file worker-with-env.php
22+
num 1
23+
}
24+
worker {
25+
file worker-with-env.php
26+
num 2
27+
}
28+
}
29+
}`
30+
31+
// Parse the configuration
32+
d := caddyfile.NewTestDispenser(configWithDuplicateFilenames)
33+
module := &FrankenPHPModule{}
34+
35+
// Unmarshal the configuration
36+
err := module.UnmarshalCaddyfile(d)
37+
38+
// Verify that an error was returned
39+
require.Error(t, err, "Expected an error when two workers in the same module have the same filename")
40+
require.Contains(t, err.Error(), "workers must not have duplicate filenames", "Error message should mention duplicate filenames")
41+
resetModuleWorkers()
42+
}
43+
44+
func TestModuleWorkersDuplicateNameFail(t *testing.T) {
45+
// Create a test configuration with a worker name
46+
configWithWorkerName1 := `
47+
{
48+
php_server {
49+
worker {
50+
name test-worker
51+
file ../testdata/worker-with-env.php
52+
num 1
53+
}
54+
}
55+
}`
56+
57+
// Parse the first configuration
58+
d1 := caddyfile.NewTestDispenser(configWithWorkerName1)
59+
module1 := &FrankenPHPModule{}
60+
61+
// Unmarshal the first configuration
62+
err := module1.UnmarshalCaddyfile(d1)
63+
require.NoError(t, err, "First module should be configured without errors")
64+
65+
// Create a second test configuration with the same worker name
66+
configWithWorkerName2 := `
67+
{
68+
php_server {
69+
worker {
70+
name test-worker
71+
file ../testdata/worker-with-env.php
72+
num 1
73+
}
74+
}
75+
}`
76+
77+
// Parse the second configuration
78+
d2 := caddyfile.NewTestDispenser(configWithWorkerName2)
79+
module2 := &FrankenPHPModule{}
80+
81+
// Unmarshal the second configuration
82+
err = module2.UnmarshalCaddyfile(d2)
83+
84+
// Verify that an error was returned
85+
require.Error(t, err, "Expected an error when two workers have the same name")
86+
require.Contains(t, err.Error(), "workers must not have duplicate names", "Error message should mention duplicate names")
87+
resetModuleWorkers()
88+
}

testdata/worker-with-env.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
22

3-
$i = 0;
4-
$env = $_SERVER['APP_ENV'];
3+
$env = $_SERVER['APP_ENV'] ?? '';
54
do {
6-
$ok = frankenphp_handle_request(function () use ($i, $env): void {
5+
$ok = frankenphp_handle_request(function () use ($env): void {
76
echo "Worker has APP_ENV=$env";
87
});
9-
10-
$i++;
118
} while ($ok);

0 commit comments

Comments
 (0)