@@ -21,6 +21,25 @@ import (
2121
2222var testPort = "9080"
2323
24+ // skipIfSymlinkNotValid skips the test if the given path is not a valid symlink
25+ func skipIfSymlinkNotValid (t * testing.T , path string ) {
26+ t .Helper ()
27+
28+ info , err := os .Lstat (path )
29+ if err != nil {
30+ t .Skipf ("symlink test skipped: cannot stat %s: %v" , path , err )
31+ }
32+
33+ if info .Mode ()& os .ModeSymlink == 0 {
34+ t .Skipf ("symlink test skipped: %s is not a symlink (git may not support symlinks on this platform)" , path )
35+ }
36+ }
37+
38+ // escapeMetricLabel escapes backslashes in label values for Prometheus text format
39+ func escapeMetricLabel (s string ) string {
40+ return strings .ReplaceAll (s , "\\ " , "\\ \\ " )
41+ }
42+
2443func TestPHP (t * testing.T ) {
2544 var wg sync.WaitGroup
2645 tester := caddytest .NewTester (t )
@@ -548,6 +567,7 @@ func TestWorkerMetrics(t *testing.T) {
548567 ` , "caddyfile" )
549568
550569 workerName , _ := fastabs .FastAbs ("../testdata/index.php" )
570+ workerName = escapeMetricLabel (workerName )
551571
552572 // Make some requests
553573 for i := range 10 {
@@ -731,6 +751,7 @@ func TestAutoWorkerConfig(t *testing.T) {
731751 ` , "caddyfile" )
732752
733753 workerName , _ := fastabs .FastAbs ("../testdata/index.php" )
754+ workerName = escapeMetricLabel (workerName )
734755
735756 // Make some requests
736757 for i := range 10 {
@@ -804,6 +825,7 @@ func TestAllDefinedServerVars(t *testing.T) {
804825 expectedBody = strings .ReplaceAll (expectedBody , "{documentRoot}" , documentRoot )
805826 expectedBody = strings .ReplaceAll (expectedBody , "\r \n " , "\n " )
806827 expectedBody = strings .ReplaceAll (expectedBody , "{testPort}" , testPort )
828+ expectedBody = strings .ReplaceAll (expectedBody , documentRoot + "/" , documentRoot + string (filepath .Separator ))
807829 tester := caddytest .NewTester (t )
808830 tester .InitServer (`
809831 {
@@ -1505,6 +1527,7 @@ func TestLog(t *testing.T) {
15051527func TestSymlinkWorkerPaths (t * testing.T ) {
15061528 cwd , _ := os .Getwd ()
15071529 publicDir := filepath .Join (cwd , ".." , "testdata" , "symlinks" , "public" )
1530+ skipIfSymlinkNotValid (t , publicDir )
15081531
15091532 t .Run ("NeighboringWorkerScript" , func (t * testing.T ) {
15101533 // Scenario: neighboring worker script
@@ -1640,6 +1663,7 @@ func TestSymlinkResolveRoot(t *testing.T) {
16401663 cwd , _ := os .Getwd ()
16411664 testDir := filepath .Join (cwd , ".." , "testdata" , "symlinks" , "test" )
16421665 publicDir := filepath .Join (cwd , ".." , "testdata" , "symlinks" , "public" )
1666+ skipIfSymlinkNotValid (t , publicDir )
16431667
16441668 t .Run ("ResolveRootSymlink" , func (t * testing.T ) {
16451669 // Tests that resolve_root_symlink directive works correctly
@@ -1698,6 +1722,7 @@ func TestSymlinkResolveRoot(t *testing.T) {
16981722func TestSymlinkWorkerBehavior (t * testing.T ) {
16991723 cwd , _ := os .Getwd ()
17001724 publicDir := filepath .Join (cwd , ".." , "testdata" , "symlinks" , "public" )
1725+ skipIfSymlinkNotValid (t , publicDir )
17011726
17021727 t .Run ("WorkerScriptFailsWithoutWorkerMode" , func (t * testing.T ) {
17031728 // Tests that accessing a worker-only script without configuring it as a worker actually results in an error
0 commit comments