-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test for common/deliverclient/blocksprovider/delivery_requester
Signed-off-by: Amrit Prakash <[email protected]>
- Loading branch information
1 parent
efd76c8
commit fef2b9c
Showing
1 changed file
with
188 additions
and
0 deletions.
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
common/deliverclient/blocksprovider/delivery_requester_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package blocksprovider_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-protos-go/common" | ||
"github.com/hyperledger/fabric/common/deliverclient/blocksprovider" | ||
"github.com/hyperledger/fabric/common/deliverclient/blocksprovider/fake" | ||
"github.com/hyperledger/fabric/common/deliverclient/orderers" | ||
"github.com/pkg/errors" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func TestDeliveryRequester_Connect_Success(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
cc := &grpc.ClientConn{} | ||
fakeDialer.DialReturns(cc, nil) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
fakeDeliverClient.SendReturns(nil) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
fakeDeliverStreamer.DeliverReturns(fakeDeliverClient, nil) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
seekInfoEnv := &common.Envelope{} | ||
endpoint := &orderers.Endpoint{ | ||
Address: "orderer-address-1", | ||
RootCerts: [][]byte{[]byte("root-cert")}, | ||
Refreshed: make(chan struct{}), | ||
} | ||
|
||
deliverClient, cancelFunc, err := dr.Connect(seekInfoEnv, endpoint) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, deliverClient) | ||
assert.NotNil(t, cancelFunc) | ||
} | ||
|
||
func TestDeliveryRequester_Connect_DialerError(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
dialError := errors.New("dialer-error") | ||
fakeDialer.DialReturns(nil, dialError) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
fakeDeliverClient.SendReturns(nil) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
fakeDeliverStreamer.DeliverReturns(fakeDeliverClient, nil) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
seekInfoEnv := &common.Envelope{} | ||
endpoint := &orderers.Endpoint{ | ||
Address: "orderer-address-1", | ||
RootCerts: [][]byte{[]byte("root-cert")}, | ||
Refreshed: make(chan struct{}), | ||
} | ||
|
||
deliverClient, cancelFunc, err := dr.Connect(seekInfoEnv, endpoint) | ||
assert.Error(t, err) | ||
assert.Equal(t, dialError, err) | ||
assert.Nil(t, deliverClient) | ||
assert.Nil(t, cancelFunc) | ||
} | ||
|
||
func TestDeliveryRequester_Connect_DeliverStreamerError(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
cc := &grpc.ClientConn{} | ||
fakeDialer.DialReturns(cc, nil) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
fakeDeliverClient.SendReturns(nil) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
deliverStreamerError := errors.New("deliver-streamer-error") | ||
fakeDeliverStreamer.DeliverReturns(nil, deliverStreamerError) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
seekInfoEnv := &common.Envelope{} | ||
endpoint := &orderers.Endpoint{ | ||
Address: "orderer-address-1", | ||
RootCerts: [][]byte{[]byte("root-cert")}, | ||
Refreshed: make(chan struct{}), | ||
} | ||
|
||
deliverClient, cancelFunc, err := dr.Connect(seekInfoEnv, endpoint) | ||
assert.Error(t, err) | ||
assert.Equal(t, deliverStreamerError, err) | ||
assert.Nil(t, deliverClient) | ||
assert.Nil(t, cancelFunc) | ||
} | ||
|
||
func TestDeliveryRequester_Connect_DeliverClientError(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
cc := &grpc.ClientConn{} | ||
fakeDialer.DialReturns(cc, nil) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
deliverClientError := errors.New("deliver-client-error") | ||
fakeDeliverClient.SendReturns(deliverClientError) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
fakeDeliverStreamer.DeliverReturns(fakeDeliverClient, nil) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
seekInfoEnv := &common.Envelope{} | ||
endpoint := &orderers.Endpoint{ | ||
Address: "orderer-address-1", | ||
RootCerts: [][]byte{[]byte("root-cert")}, | ||
Refreshed: make(chan struct{}), | ||
} | ||
|
||
deliverClient, cancelFunc, err := dr.Connect(seekInfoEnv, endpoint) | ||
assert.Error(t, err) | ||
assert.Equal(t, deliverClientError, err) | ||
assert.Nil(t, deliverClient) | ||
assert.Nil(t, cancelFunc) | ||
} | ||
|
||
func TestDeliveryRequester_SeekInfoBlocksFrom(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
cc := &grpc.ClientConn{} | ||
fakeDialer.DialReturns(cc, nil) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
fakeDeliverClient.SendReturns(nil) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
fakeDeliverStreamer.DeliverReturns(fakeDeliverClient, nil) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
envelope, err := dr.SeekInfoBlocksFrom(1000) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, envelope) | ||
} | ||
|
||
func TestDeliveryRequester_SeekInfoHeadersFrom(t *testing.T) { | ||
fakeSigner := &fake.Signer{} | ||
fakeSigner.SignReturns([]byte("good-sig"), nil) | ||
|
||
fakeDialer := &fake.Dialer{} | ||
cc := &grpc.ClientConn{} | ||
fakeDialer.DialReturns(cc, nil) | ||
|
||
fakeDeliverClient := &fake.DeliverClient{} | ||
fakeDeliverClient.SendReturns(nil) | ||
|
||
fakeDeliverStreamer := &fake.DeliverStreamer{} | ||
fakeDeliverStreamer.DeliverReturns(fakeDeliverClient, nil) | ||
|
||
dr := blocksprovider.NewDeliveryRequester("channel-id", fakeSigner, []byte("tls-cert-hash"), fakeDialer, fakeDeliverStreamer) | ||
assert.NotNil(t, dr) | ||
|
||
envelope, err := dr.SeekInfoHeadersFrom(1000) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, envelope) | ||
} |