Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 4f3f0c0

Browse files
committed
Move websocket test server to its own package
1 parent 758d14b commit 4f3f0c0

File tree

3 files changed

+146
-140
lines changed

3 files changed

+146
-140
lines changed

common/connection_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ import (
3333
"github.com/mailru/easyjson"
3434
"github.com/stretchr/testify/assert"
3535
"github.com/stretchr/testify/require"
36+
37+
"github.com/grafana/xk6-browser/tests/ws"
3638
)
3739

3840
func TestConnection(t *testing.T) {
39-
server := NewWSServerWithEcho(t)
41+
server := ws.NewWSServerWithEcho(t)
4042
defer server.Cleanup()
4143

4244
t.Run("connect", func(t *testing.T) {
@@ -51,7 +53,7 @@ func TestConnection(t *testing.T) {
5153
}
5254

5355
func TestConnectionClosureAbnormal(t *testing.T) {
54-
server := NewWSServerWithClosureAbnormal(t)
56+
server := ws.NewWSServerWithClosureAbnormal(t)
5557
defer server.Cleanup()
5658

5759
t.Run("closure abnormal", func(t *testing.T) {
@@ -69,7 +71,7 @@ func TestConnectionClosureAbnormal(t *testing.T) {
6971
}
7072

7173
func TestConnectionSendRecv(t *testing.T) {
72-
server := NewWSServerWithCDPHandler(t, CDPDefaultHandler, nil)
74+
server := ws.NewWSServerWithCDPHandler(t, ws.CDPDefaultHandler, nil)
7375
defer server.Cleanup()
7476

7577
t.Run("send command with empty reply", func(t *testing.T) {
@@ -133,7 +135,7 @@ func TestConnectionCreateSession(t *testing.T) {
133135
}
134136
}
135137

136-
server := NewWSServerWithCDPHandler(t, handler, &cmdsReceived)
138+
server := ws.NewWSServerWithCDPHandler(t, handler, &cmdsReceived)
137139
defer server.Cleanup()
138140

139141
t.Run("create session for target", func(t *testing.T) {

common/session_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"github.com/mailru/easyjson"
3535
"github.com/stretchr/testify/assert"
3636
"github.com/stretchr/testify/require"
37+
38+
"github.com/grafana/xk6-browser/tests/ws"
3739
)
3840

3941
func TestSessionCreateSession(t *testing.T) {
@@ -59,18 +61,18 @@ func TestSessionCreateSession(t *testing.T) {
5961
case cdproto.MethodType(cdproto.CommandTargetAttachToTarget):
6062
writeCh <- cdproto.Message{
6163
Method: cdproto.EventTargetAttachedToTarget,
62-
Params: easyjson.RawMessage([]byte(DEFAULT_CDP_TARGET_ATTACHED_TO_TARGET_MSG)),
64+
Params: easyjson.RawMessage([]byte(ws.CDPTargetAttachedToTargetRequest)),
6365
}
6466
writeCh <- cdproto.Message{
6567
ID: msg.ID,
6668
SessionID: msg.SessionID,
67-
Result: easyjson.RawMessage([]byte(DEFAULT_CDP_TARGET_ATTACH_TO_TARGET_RESPONSE)),
69+
Result: easyjson.RawMessage([]byte(ws.CDPTargetAttachedToTargetResponse)),
6870
}
6971
}
7072
}
7173
}
7274

73-
server := NewWSServerWithCDPHandler(t, handler, &cmdsReceived)
75+
server := ws.NewWSServerWithCDPHandler(t, handler, &cmdsReceived)
7476
defer server.Cleanup()
7577

7678
t.Run("send and recv session commands", func(t *testing.T) {
@@ -81,9 +83,9 @@ func TestSessionCreateSession(t *testing.T) {
8183

8284
if assert.NoError(t, err) {
8385
session, err := conn.createSession(&target.Info{
84-
TargetID: DEFAULT_CDP_TARGET_ID,
86+
TargetID: ws.DummyCDPTargetID,
8587
Type: "page",
86-
BrowserContextID: DEFAULT_CDP_BROWSER_CONTEXT_ID,
88+
BrowserContextID: ws.DummyCDPBrowserContextID,
8789
})
8890

8991
if assert.NoError(t, err) {

0 commit comments

Comments
 (0)