github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/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  	"github.com/hyperledger/fabric/gossip/api"
    13  	"github.com/hyperledger/fabric/gossip/common"
    14  	proto "github.com/hyperledger/fabric/protos/gossip"
    15  	"github.com/stretchr/testify/assert"
    16  	"github.com/stretchr/testify/mock"
    17  )
    18  
    19  func TestGossipMock(t *testing.T) {
    20  	g := GossipMock{}
    21  	mkChan := func() <-chan *proto.GossipMessage {
    22  		c := make(chan *proto.GossipMessage, 1)
    23  		c <- &proto.GossipMessage{}
    24  		return c
    25  	}
    26  	g.On("Accept", mock.Anything, false).Return(mkChan(), nil)
    27  	a, b := g.Accept(func(o interface{}) bool {
    28  		return true
    29  	}, false)
    30  	assert.Nil(t, b)
    31  	assert.NotNil(t, a)
    32  	assert.Panics(t, func() {
    33  		g.SuspectPeers(func(identity api.PeerIdentityType) bool { return false })
    34  	})
    35  	assert.Panics(t, func() {
    36  		g.Send(nil, nil)
    37  	})
    38  	assert.Panics(t, func() {
    39  		g.Peers()
    40  	})
    41  	assert.Empty(t, g.PeersOfChannel(common.ChainID("A")))
    42  
    43  	assert.Panics(t, func() {
    44  		g.UpdateMetadata([]byte{})
    45  	})
    46  	assert.Panics(t, func() {
    47  		g.Gossip(nil)
    48  	})
    49  	assert.NotPanics(t, func() {
    50  		g.UpdateChannelMetadata([]byte{}, common.ChainID("A"))
    51  		g.Stop()
    52  		g.JoinChan(nil, common.ChainID("A"))
    53  	})
    54  }