@@ -2,14 +2,14 @@ package dap
22
33import (
44 "context"
5- "encoding/json"
65 "fmt"
76 "io"
87 "path/filepath"
98 "testing"
109 "time"
1110
1211 "github.com/docker/buildx/dap/common"
12+ "github.com/docker/buildx/util/daptest"
1313 "github.com/google/go-dap"
1414 "github.com/moby/buildkit/solver/pb"
1515 "github.com/stretchr/testify/assert"
@@ -36,20 +36,20 @@ func TestLaunch(t *testing.T) {
3636
3737 client .RegisterEvent ("initialized" , func (em dap.EventMessage ) {
3838 // Send configuration done since we don't do any configuration.
39- configurationDone = DoRequest [* dap.ConfigurationDoneResponse ](t , client , & dap.ConfigurationDoneRequest {
39+ configurationDone = daptest . DoRequest [* dap.ConfigurationDoneResponse ](t , client , & dap.ConfigurationDoneRequest {
4040 Request : dap.Request {Command : "configurationDone" },
4141 })
4242 close (initialized )
4343 })
4444
4545 eg .Go (func () error {
46- initializeResp := <- DoRequest [* dap.InitializeResponse ](t , client , & dap.InitializeRequest {
46+ initializeResp := <- daptest . DoRequest [* dap.InitializeResponse ](t , client , & dap.InitializeRequest {
4747 Request : dap.Request {Command : "initialize" },
4848 })
4949 assert .True (t , initializeResp .Success )
5050 assert .True (t , initializeResp .Body .SupportsConfigurationDoneRequest )
5151
52- launchResp := <- DoRequest [* dap.LaunchResponse ](t , client , & dap.LaunchRequest {
52+ launchResp := <- daptest . DoRequest [* dap.LaunchResponse ](t , client , & dap.LaunchRequest {
5353 Request : dap.Request {Command : "launch" },
5454 })
5555 assert .True (t , launchResp .Success )
@@ -93,7 +93,7 @@ func TestSetBreakpoints(t *testing.T) {
9393 )
9494
9595 client .RegisterEvent ("initialized" , func (em dap.EventMessage ) {
96- setBreakpoints = DoRequest [* dap.SetBreakpointsResponse ](t , client , & dap.SetBreakpointsRequest {
96+ setBreakpoints = daptest . DoRequest [* dap.SetBreakpointsResponse ](t , client , & dap.SetBreakpointsRequest {
9797 Request : dap.Request {Command : "setBreakpoints" },
9898 Arguments : dap.SetBreakpointsArguments {
9999 Source : dap.Source {Name : "Dockerfile" , Path : filepath .Join (t .TempDir (), "Dockerfile" )},
@@ -104,13 +104,13 @@ func TestSetBreakpoints(t *testing.T) {
104104 })
105105
106106 eg .Go (func () error {
107- initializeResp := <- DoRequest [* dap.InitializeResponse ](t , client , & dap.InitializeRequest {
107+ initializeResp := <- daptest . DoRequest [* dap.InitializeResponse ](t , client , & dap.InitializeRequest {
108108 Request : dap.Request {Command : "initialize" },
109109 })
110110 assert .True (t , initializeResp .Success )
111111 assert .True (t , initializeResp .Body .SupportsConfigurationDoneRequest )
112112
113- launchResp := <- DoRequest [* dap.LaunchResponse ](t , client , & dap.LaunchRequest {
113+ launchResp := <- daptest . DoRequest [* dap.LaunchResponse ](t , client , & dap.LaunchRequest {
114114 Request : dap.Request {Command : "launch" },
115115 })
116116 assert .True (t , launchResp .Success )
@@ -234,66 +234,29 @@ func TestBreakpointMapIntersectVerified(t *testing.T) {
234234 }
235235}
236236
237- func NewTestAdapter [C LaunchConfig ](t * testing.T ) (* Adapter [C ], Conn , * Client ) {
237+ func NewTestAdapter [C LaunchConfig ](t * testing.T ) (* Adapter [C ], Conn , * daptest. Client ) {
238238 t .Helper ()
239239
240240 rd1 , wr1 := io .Pipe ()
241241 rd2 , wr2 := io .Pipe ()
242242
243- srvConn := logConn (t , "server" , NewConn (rd1 , wr2 ))
243+ srvConn := daptest . LogConn (t , "server" , NewConn (rd1 , wr2 ))
244244 t .Cleanup (func () {
245245 srvConn .Close ()
246246 })
247247
248- clientConn := logConn (t , "client" , NewConn (rd2 , wr1 ))
248+ clientConn := daptest . LogConn (t , "client" , NewConn (rd2 , wr1 ))
249249 t .Cleanup (func () { clientConn .Close () })
250250
251251 adapter := New [C ]()
252252 t .Cleanup (func () { adapter .Stop () })
253253
254- client := NewClient (clientConn )
254+ client := daptest . NewClient (clientConn )
255255 t .Cleanup (func () { client .Close () })
256256
257257 return adapter , srvConn , client
258258}
259259
260- func logConn (t * testing.T , prefix string , conn Conn ) Conn {
261- return & loggingConn {
262- Conn : conn ,
263- t : t ,
264- prefix : prefix ,
265- }
266- }
267-
268- type loggingConn struct {
269- Conn
270- t * testing.T
271- prefix string
272- }
273-
274- func (c * loggingConn ) SendMsg (m dap.Message ) error {
275- b , _ := json .Marshal (m )
276- c .t .Logf ("[%s] send: %v" , c .prefix , string (b ))
277-
278- err := c .Conn .SendMsg (m )
279- if err != nil {
280- c .t .Logf ("[%s] send error: %v" , c .prefix , err )
281- }
282- return err
283- }
284-
285- func (c * loggingConn ) RecvMsg (ctx context.Context ) (dap.Message , error ) {
286- m , err := c .Conn .RecvMsg (ctx )
287- if err != nil {
288- c .t .Logf ("[%s] recv error: %v" , c .prefix , err )
289- return nil , err
290- }
291-
292- b , _ := json .Marshal (m )
293- c .t .Logf ("[%s] recv: %v" , c .prefix , string (b ))
294- return m , nil
295- }
296-
297260type breakpointTestContext struct {
298261 context.Context
299262 messages chan dap.Message
0 commit comments