github.com/yimialmonte/fabric@v2.1.1+incompatible/gossip/state/mocks/gossip_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package mocks
     8  
     9  import (
    10  	"testing"
    11  
    12  	proto "github.com/hyperledger/fabric-protos-go/gossip"
    13  	"github.com/hyperledger/fabric/gossip/api"
    14  	"github.com/hyperledger/fabric/gossip/common"
    15  	"github.com/hyperledger/fabric/gossip/discovery"
    16  	"github.com/stretchr/testify/assert"
    17  	"github.com/stretchr/testify/mock"
    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  	assert.Nil(t, b)
    32  	assert.NotNil(t, a)
    33  	assert.Panics(t, func() {
    34  		g.SuspectPeers(func(identity api.PeerIdentityType) bool { return false })
    35  	})
    36  	assert.Panics(t, func() {
    37  		g.Send(nil, nil)
    38  	})
    39  	assert.Panics(t, func() {
    40  		g.Peers()
    41  	})
    42  	g.On("PeersOfChannel", mock.Anything).Return([]discovery.NetworkMember{})
    43  	assert.Empty(t, g.PeersOfChannel(common.ChannelID("A")))
    44  
    45  	assert.Panics(t, func() {
    46  		g.UpdateMetadata([]byte{})
    47  	})
    48  	assert.Panics(t, func() {
    49  		g.Gossip(nil)
    50  	})
    51  	assert.NotPanics(t, func() {
    52  		g.UpdateLedgerHeight(0, common.ChannelID("A"))
    53  		g.Stop()
    54  		g.JoinChan(nil, common.ChannelID("A"))
    55  	})
    56  }