github.com/turingchain2020/turingchain@v1.1.21/client/mock_p2p_test.go (about) 1 // Copyright Turing Corp. 2018 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 client_test 6 7 import ( 8 "github.com/turingchain2020/turingchain/queue" 9 "github.com/turingchain2020/turingchain/types" 10 ) 11 12 type mockP2P struct { 13 } 14 15 func (m *mockP2P) SetQueueClient(q queue.Queue) { 16 go func() { 17 p2pKey := "p2p" 18 client := q.Client() 19 client.Sub(p2pKey) 20 for msg := range client.Recv() { 21 switch msg.Ty { 22 case types.EventPeerInfo: 23 msg.Reply(client.NewMessage(p2pKey, types.EventPeerList, &types.PeerList{})) 24 case types.EventGetNetInfo: 25 msg.Reply(client.NewMessage(p2pKey, types.EventPeerList, &types.NodeNetInfo{})) 26 default: 27 msg.ReplyErr("Do not support", types.ErrNotSupport) 28 } 29 } 30 }() 31 } 32 33 func (m *mockP2P) Close() { 34 }