go-hep.org/x/hep@v0.38.1/xrootd/ping_mock_test.go (about) 1 // Copyright ©2018 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package xrootd // import "go-hep.org/x/hep/xrootd" 6 7 import ( 8 "context" 9 "net" 10 "testing" 11 12 "go-hep.org/x/hep/xrootd/xrdproto" 13 "go-hep.org/x/hep/xrootd/xrdproto/ping" 14 ) 15 16 func TestSession_Ping_Mock(t *testing.T) { 17 serverFunc := func(cancel func(), conn net.Conn) { 18 data, err := xrdproto.ReadRequest(conn) 19 if err != nil { 20 cancel() 21 t.Fatalf("could not read request: %v", err) 22 } 23 24 var gotRequest ping.Request 25 gotHeader, err := unmarshalRequest(data, &gotRequest) 26 if err != nil { 27 cancel() 28 t.Fatalf("could not unmarshal request: %v", err) 29 } 30 31 err = xrdproto.WriteResponse(conn, gotHeader.StreamID, xrdproto.Ok, nil) 32 if err != nil { 33 cancel() 34 t.Fatalf("could not write response: %v", err) 35 } 36 } 37 38 clientFunc := func(cancel func(), client *Client) { 39 err := client.sessions[client.initialSessionID].Ping(context.Background()) 40 if err != nil { 41 t.Fatalf("invalid ping call: %v", err) 42 } 43 } 44 45 testClientWithMockServer(serverFunc, clientFunc) 46 }