github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/gossip/state/mocks/gossip_test.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package mocks 8 9 import ( 10 "testing" 11 12 "github.com/hechain20/hechain/gossip/api" 13 "github.com/hechain20/hechain/gossip/common" 14 "github.com/hechain20/hechain/gossip/discovery" 15 proto "github.com/hyperledger/fabric-protos-go/gossip" 16 "github.com/stretchr/testify/mock" 17 "github.com/stretchr/testify/require" 18 ) 19 20 func TestGossipMock(t *testing.T) { 21 g := GossipMock{} 22 mkChan := func() <-chan *proto.GossipMessage { 23 c := make(chan *proto.GossipMessage, 1) 24 c <- &proto.GossipMessage{} 25 return c 26 } 27 g.On("Accept", mock.Anything, false).Return(mkChan(), nil) 28 a, b := g.Accept(func(o interface{}) bool { 29 return true 30 }, false) 31 require.Nil(t, b) 32 require.NotNil(t, a) 33 require.Panics(t, func() { 34 g.SuspectPeers(func(identity api.PeerIdentityType) bool { return false }) 35 }) 36 require.Panics(t, func() { 37 g.Send(nil, nil) 38 }) 39 require.Panics(t, func() { 40 g.Peers() 41 }) 42 g.On("PeersOfChannel", mock.Anything).Return([]discovery.NetworkMember{}) 43 require.Empty(t, g.PeersOfChannel(common.ChannelID("A"))) 44 45 require.Panics(t, func() { 46 g.UpdateMetadata([]byte{}) 47 }) 48 require.Panics(t, func() { 49 g.Gossip(nil) 50 }) 51 require.NotPanics(t, func() { 52 g.UpdateLedgerHeight(0, common.ChannelID("A")) 53 g.Stop() 54 g.JoinChan(nil, common.ChannelID("A")) 55 }) 56 }