Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IndraGunawan committed Feb 10, 2025
1 parent 4b66348 commit bcc320c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions caddy/caddy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package caddy_test

import (
"bytes"
"context"
"fmt"
"net/http"
"os"
Expand All @@ -11,10 +12,10 @@ import (
"testing"

"github.com/dunglas/frankenphp"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddytest"
)

Expand Down Expand Up @@ -317,6 +318,7 @@ func TestPHPServerDirectiveDisableFileServer(t *testing.T) {

func TestMetrics(t *testing.T) {
var wg sync.WaitGroup
ctx, _ := caddy.NewContext(caddy.Context{Context: context.Background()})
tester := caddytest.NewTester(t)
tester.InitServer(`
{
Expand Down Expand Up @@ -374,11 +376,12 @@ func TestMetrics(t *testing.T) {
frankenphp_busy_threads 0
`

require.NoError(t, testutil.GatherAndCompare(prometheus.DefaultGatherer, strings.NewReader(expectedMetrics), "frankenphp_total_threads", "frankenphp_busy_threads"))
require.NoError(t, testutil.GatherAndCompare(ctx.GetMetricsRegistry(), strings.NewReader(expectedMetrics), "frankenphp_total_threads", "frankenphp_busy_threads"))
}

func TestWorkerMetrics(t *testing.T) {
var wg sync.WaitGroup
ctx, _ := caddy.NewContext(caddy.Context{Context: context.Background()})
tester := caddytest.NewTester(t)
tester.InitServer(`
{
Expand Down Expand Up @@ -464,7 +467,7 @@ func TestWorkerMetrics(t *testing.T) {

require.NoError(t,
testutil.GatherAndCompare(
prometheus.DefaultGatherer,
ctx.GetMetricsRegistry(),
strings.NewReader(expectedMetrics),
"frankenphp_total_threads",
"frankenphp_busy_threads",
Expand All @@ -479,6 +482,7 @@ func TestWorkerMetrics(t *testing.T) {

func TestAutoWorkerConfig(t *testing.T) {
var wg sync.WaitGroup
ctx, _ := caddy.NewContext(caddy.Context{Context: context.Background()})
tester := caddytest.NewTester(t)
tester.InitServer(`
{
Expand Down Expand Up @@ -565,7 +569,7 @@ func TestAutoWorkerConfig(t *testing.T) {

require.NoError(t,
testutil.GatherAndCompare(
prometheus.DefaultGatherer,
ctx.GetMetricsRegistry(),
strings.NewReader(expectedMetrics),
"frankenphp_total_threads",
"frankenphp_busy_threads",
Expand Down

0 comments on commit bcc320c

Please # to comment.