Also moves php_headers test.

This commit is contained in:
Alliballibaba
2025-11-01 22:37:35 +01:00
parent 6dc34328ba
commit 7c8813ee6d
2 changed files with 22 additions and 15 deletions

View File

@@ -0,0 +1,22 @@
package phpheaders
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAllCommonHeadersAreCorrect(t *testing.T) {
fakeRequest := httptest.NewRequest("GET", "http://localhost", nil)
for header, phpHeader := range CommonRequestHeaders {
// verify that common and uncommon headers return the same result
expectedPHPHeader := GetUnCommonHeader(header)
assert.Equal(t, phpHeader+"\x00", expectedPHPHeader, "header is not well formed: "+phpHeader)
// net/http will capitalize lowercase headers, verify that headers are capitalized
fakeRequest.Header.Add(header, "foo")
assert.Contains(t, fakeRequest.Header, header, "header is not correctly capitalized: "+header)
}
}

View File

@@ -12,7 +12,6 @@ import (
"testing"
"time"
"github.com/dunglas/frankenphp/internal/phpheaders"
"github.com/dunglas/frankenphp/internal/state"
"github.com/stretchr/testify/assert"
)
@@ -237,20 +236,6 @@ func allPossibleTransitions(worker1Path string, worker2Path string) []func(*phpT
}
}
func TestAllCommonHeadersAreCorrect(t *testing.T) {
fakeRequest := httptest.NewRequest("GET", "http://localhost", nil)
for header, phpHeader := range phpheaders.CommonRequestHeaders {
// verify that common and uncommon headers return the same result
expectedPHPHeader := phpheaders.GetUnCommonHeader(header)
assert.Equal(t, phpHeader+"\x00", expectedPHPHeader, "header is not well formed: "+phpHeader)
// net/http will capitalize lowercase headers, verify that headers are capitalized
fakeRequest.Header.Add(header, "foo")
assert.Contains(t, fakeRequest.Header, header, "header is not correctly capitalized: "+header)
}
}
func TestCorrectThreadCalculation(t *testing.T) {
maxProcs := runtime.GOMAXPROCS(0) * 2
oneWorkerThread := []workerOpt{{num: 1}}