-
Notifications
You must be signed in to change notification settings - Fork 2
/
transport_test.go
47 lines (40 loc) · 1.33 KB
/
transport_test.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package rsocket_transport_quic_test
import (
"context"
"log"
"testing"
rsocket_transport_quic "github.com/jjeffcaii/rsocket-transport-quic"
"github.com/rsocket/rsocket-go"
"github.com/rsocket/rsocket-go/payload"
"github.com/rsocket/rsocket-go/rx/mono"
"github.com/stretchr/testify/assert"
)
var fakeRequest = payload.NewString("fake data", "fake metadata")
func TestQUICServerTransport_Accept(t *testing.T) {
started := make(chan struct{})
go func() {
err := rsocket.Receive().
OnStart(func() {
close(started)
}).
Acceptor(func(setup payload.SetupPayload, sendingSocket rsocket.CloseableRSocket) (responder rsocket.RSocket, err error) {
responder = rsocket.NewAbstractSocket(
rsocket.RequestResponse(func(request payload.Payload) mono.Mono {
return mono.Just(request)
}),
)
return
}).
Transport(rsocket_transport_quic.Server().SetAddr(":443").Build()).
Serve(context.Background())
log.Fatalln(err)
}()
client, err := rsocket.Connect().
Transport(rsocket_transport_quic.Client().SetAddr("127.0.0.1:443").Build()).
Start(context.Background())
assert.NoError(t, err, "connect failed")
defer client.Close()
response, err := client.RequestResponse(fakeRequest).Block(context.Background())
assert.NoError(t, err, "request failed")
assert.True(t, payload.Equal(fakeRequest, response))
}