-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathmercure_test.go
More file actions
32 lines (26 loc) · 1021 Bytes
/
mercure_test.go
File metadata and controls
32 lines (26 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//go:build !nomercure
package frankenphp_test
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/dunglas/frankenphp"
"github.com/dunglas/mercure"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMercurePublish_module(t *testing.T) { testMercurePublish(t, &testOptions{}) }
func TestMercurePublish_worker(t *testing.T) {
testMercurePublish(t, &testOptions{workerScript: "index.php"})
}
func testMercurePublish(t *testing.T, opts *testOptions) {
h, err := mercure.NewHub(t.Context(), mercure.WithTransport(mercure.NewLocalTransport(mercure.NewSubscriberList(0))))
require.NoError(t, err)
opts.requestOpts = []frankenphp.RequestOption{frankenphp.WithMercureHub(h)}
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
body, _ := testGet(fmt.Sprintf("https://example.com/mercure-publish.php?i=%d", i), handler, t)
assert.Contains(t, body, "update 1: ")
assert.Contains(t, body, "update 2: ")
}, opts)
}