Skip to content

Commit 176b4a4

Browse files
committed
get rid of zapslog
1 parent 5579fb3 commit 176b4a4

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

frankenphp_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ import (
3232
"github.com/dunglas/frankenphp/internal/fastabs"
3333
"github.com/stretchr/testify/assert"
3434
"github.com/stretchr/testify/require"
35-
"go.uber.org/zap/exp/zapslog"
36-
"go.uber.org/zap/zapcore"
37-
"go.uber.org/zap/zaptest"
38-
"go.uber.org/zap/zaptest/observer"
3935
)
4036

4137
type testOptions struct {
@@ -62,10 +58,6 @@ func runTest(t *testing.T, test func(func(http.ResponseWriter, *http.Request), *
6258
cwd, _ := os.Getwd()
6359
testDataDir := cwd + "/testdata/"
6460

65-
if opts.logger == nil {
66-
opts.logger = slog.New(zapslog.NewHandler(zaptest.NewLogger(t).Core()))
67-
}
68-
6961
initOpts := []frankenphp.Option{frankenphp.WithLogger(opts.logger)}
7062
if opts.workerScript != "" {
7163
workerOpts := []frankenphp.WorkerOption{
@@ -468,24 +460,24 @@ func testLog_frankenphp_log(t *testing.T, opts *testOptions) {
468460

469461
func TestConnectionAbort_module(t *testing.T) { testConnectionAbort(t, &testOptions{}) }
470462
func TestConnectionAbort_worker(t *testing.T) {
471-
testConnectionAbort(t, &testOptions{workerScript: "connectionStatusLog.php"})
463+
testConnectionAbort(t, &testOptions{workerScript: "connection_status.php"})
472464
}
473465
func testConnectionAbort(t *testing.T, opts *testOptions) {
474466
testFinish := func(finish string) {
475467
t.Run(fmt.Sprintf("finish=%s", finish), func(t *testing.T) {
476-
logger, logs := observer.New(zapcore.InfoLevel)
477-
opts.logger = slog.New(zapslog.NewHandler(logger))
468+
var buf bytes.Buffer
469+
opts.logger = slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo}))
478470

479471
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
480-
req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/connectionStatusLog.php?i=%d&finish=%s", i, finish), nil)
472+
req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/connection_status.php?i=%d&finish=%s", i, finish), nil)
481473
w := httptest.NewRecorder()
482474

483475
ctx, cancel := context.WithCancel(req.Context())
484476
req = req.WithContext(ctx)
485477
cancel()
486478
handler(w, req)
487479

488-
for logs.FilterMessage(fmt.Sprintf("request %d: 1", i)).Len() <= 0 {
480+
for !strings.Contains(buf.String(), fmt.Sprintf("request %d: 1", i)) {
489481
}
490482
}, opts)
491483
})

worker_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package frankenphp_test
22

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"log"
@@ -17,9 +18,6 @@ import (
1718

1819
"github.com/dunglas/frankenphp"
1920
"github.com/stretchr/testify/assert"
20-
"go.uber.org/zap/exp/zapslog"
21-
"go.uber.org/zap/zapcore"
22-
"go.uber.org/zap/zaptest/observer"
2321
)
2422

2523
func TestWorker(t *testing.T) {
@@ -97,8 +95,8 @@ func TestWorkerEnv(t *testing.T) {
9795
}
9896

9997
func TestWorkerGetOpt(t *testing.T) {
100-
obs, logs := observer.New(zapcore.InfoLevel)
101-
logger := slog.New(zapslog.NewHandler(obs))
98+
var buf bytes.Buffer
99+
logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo}))
102100

103101
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
104102
req := httptest.NewRequest("GET", fmt.Sprintf("http://example.com/worker-getopt.php?i=%d", i), nil)
@@ -114,9 +112,7 @@ func TestWorkerGetOpt(t *testing.T) {
114112
assert.Contains(t, string(body), fmt.Sprintf("[REQUEST_URI] => /worker-getopt.php?i=%d", i))
115113
}, &testOptions{logger: logger, workerScript: "worker-getopt.php", env: map[string]string{"FOO": "bar"}})
116114

117-
for _, l := range logs.FilterFieldKey("exit_status").All() {
118-
assert.Failf(t, "unexpected exit status", "exit status: %d", l.ContextMap()["exit_status"])
119-
}
115+
assert.NotContains(t, buf.String(), "exit_status")
120116
}
121117

122118
func ExampleServeHTTP_workers() {

0 commit comments

Comments
 (0)