Skip to content

Commit

Permalink
[FAB-10511] clean up sdk log calls
Browse files Browse the repository at this point in the history
Change-Id: Id5a5c3689437a59b3ca026b3403943aab057d991
Signed-off-by: Baha Shaaban <baha.shaaban@securekey.com>
  • Loading branch information
Baha Shaaban committed Jun 1, 2018
1 parent 38d3ff8 commit 81694dd
Show file tree
Hide file tree
Showing 163 changed files with 1,127 additions and 1,125 deletions.
30 changes: 15 additions & 15 deletions pkg/client/channel/chclient_test.go
Expand Up @@ -48,7 +48,7 @@ func TestTxProposalResponseFilter(t *testing.T) {

_, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed for not success status")
t.Fatal("Should have failed for not success status")
}
statusError, ok := status.FromError(err)
assert.True(t, ok, "Expected status error")
Expand All @@ -62,7 +62,7 @@ func TestTxProposalResponseFilter(t *testing.T) {
chClient = setupChannelClient(peers, t)
_, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed for not success status")
t.Fatal("Should have failed for not success status")
}
statusError, ok = status.FromError(err)
assert.True(t, ok, "Expected status error")
Expand All @@ -77,17 +77,17 @@ func TestQuery(t *testing.T) {

_, err := chClient.Query(Request{})
if err == nil {
t.Fatalf("Should have failed for empty query request")
t.Fatal("Should have failed for empty query request")
}

_, err = chClient.Query(Request{Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed for empty chaincode ID")
t.Fatal("Should have failed for empty chaincode ID")
}

_, err = chClient.Query(Request{ChaincodeID: "testCC", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed for empty function")
t.Fatal("Should have failed for empty function")
}

response, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
Expand All @@ -107,7 +107,7 @@ func TestQuery(t *testing.T) {
chClient = setupChannelClient([]fab.Peer{testPeer1, testPeer2}, t)
_, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed")
t.Fatal("Should have failed")
}
s, ok := status.FromError(err)
assert.True(t, ok, "expected status error")
Expand All @@ -120,7 +120,7 @@ func TestQuerySelectionError(t *testing.T) {

_, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed to query with error in selection.GetEndorsersFor ...")
t.Fatal("Should have failed to query with error in selection.GetEndorsersFor ...")
}
}

Expand Down Expand Up @@ -182,14 +182,14 @@ func TestQueryWithNilTargets(t *testing.T) {
_, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",
Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(nil, nil))
if err == nil || !strings.Contains(err.Error(), "target is nil") {
t.Fatalf("Should have failed to invoke test cc due to nil target")
t.Fatal("Should have failed to invoke test cc due to nil target")
}

peers := []fab.Peer{fcmocks.NewMockPeer("Peer1", "http://peer1.com"), nil}
_, err = chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke",
Args: [][]byte{[]byte("query"), []byte("b")}}, WithTargets(peers...))
if err == nil || !strings.Contains(err.Error(), "target is nil") {
t.Fatalf("Should have failed to invoke test cc due to nil target")
t.Fatal("Should have failed to invoke test cc due to nil target")
}
}

Expand All @@ -198,17 +198,17 @@ func TestExecuteTx(t *testing.T) {

_, err := chClient.Execute(Request{})
if err == nil {
t.Fatalf("Should have failed for empty invoke request")
t.Fatal("Should have failed for empty invoke request")
}

_, err = chClient.Execute(Request{Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})
if err == nil {
t.Fatalf("Should have failed for empty chaincode ID")
t.Fatal("Should have failed for empty chaincode ID")
}

_, err = chClient.Execute(Request{ChaincodeID: "testCC", Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})
if err == nil {
t.Fatalf("Should have failed for empty function")
t.Fatal("Should have failed for empty function")
}

// Test return different payload
Expand All @@ -219,7 +219,7 @@ func TestExecuteTx(t *testing.T) {
chClient = setupChannelClient([]fab.Peer{testPeer1, testPeer2}, t)
_, err = chClient.Execute(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("move"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed")
t.Fatal("Should have failed")
}
s, ok := status.FromError(err)
assert.True(t, ok, "expected status error")
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestExecuteTxSelectionError(t *testing.T) {
_, err := chClient.Execute(Request{ChaincodeID: "testCC", Fcn: "invoke",
Args: [][]byte{[]byte("move"), []byte("a"), []byte("b"), []byte("1")}})
if err == nil {
t.Fatalf("Should have failed to execute tx with error in selection.GetEndorserrsFor ...")
t.Fatal("Should have failed to execute tx with error in selection.GetEndorserrsFor ...")
}
}

Expand All @@ -333,7 +333,7 @@ func TestRPCStatusErrorPropagation(t *testing.T) {

_, err := chClient.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err == nil {
t.Fatalf("Should have failed for not success status")
t.Fatal("Should have failed for not success status")
}
statusError, ok := status.FromError(err)
assert.True(t, ok, "Expected status error")
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/channel/example_test.go
Expand Up @@ -22,7 +22,7 @@ func Example() {

response, err := c.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("data")}})
if err != nil {
fmt.Printf("failed to query chaincode: %v", err)
fmt.Printf("failed to query chaincode: %s", err)
}

fmt.Println(string(response.Payload))
Expand Down Expand Up @@ -58,7 +58,7 @@ func ExampleClient_Query() {

response, err := c.Query(Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("b")}})
if err != nil {
fmt.Printf("failed to query chaincode: %v", err)
fmt.Printf("failed to query chaincode: %s", err)
}

if len(response.Payload) > 0 {
Expand Down Expand Up @@ -113,7 +113,7 @@ func ExampleClient_InvokeHandler() {

response, err := c.InvokeHandler(&exampleHandler{}, Request{ChaincodeID: "testCC", Fcn: "invoke", Args: [][]byte{[]byte("query"), []byte("data")}})
if err != nil {
fmt.Printf("failed to query chaincode: %v", err)
fmt.Printf("failed to query chaincode: %s", err)
}

fmt.Println(string(response.Payload))
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/channel/invoke/txnhandler_test.go
Expand Up @@ -232,7 +232,7 @@ func TestProposalProcessorHandlerPassDirectly(t *testing.T) {
t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.Targets))
}
if requestContext.Opts.Targets[0] != peer2 {
t.Fatalf("Didn't get expected peers")
t.Fatal("Didn't get expected peers")
}
}

Expand All @@ -252,7 +252,7 @@ func TestProposalProcessorHandler(t *testing.T) {
t.Fatalf("Expecting %d proposal processors but got %d", len(discoveryPeers), len(requestContext.Opts.Targets))
}
if requestContext.Opts.Targets[0] != peer1 || requestContext.Opts.Targets[1] != peer2 {
t.Fatalf("Didn't get expected peers")
t.Fatal("Didn't get expected peers")
}

requestContext = prepareRequestContext(request, Opts{TargetFilter: &filter{peer: peer2}}, t)
Expand All @@ -264,7 +264,7 @@ func TestProposalProcessorHandler(t *testing.T) {
t.Fatalf("Expecting 1 proposal processor but got %d", len(requestContext.Opts.Targets))
}
if requestContext.Opts.Targets[0] != peer2 {
t.Fatalf("Didn't get expected peers")
t.Fatal("Didn't get expected peers")
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/common/discovery/discoveryfilter_test.go
Expand Up @@ -60,7 +60,7 @@ func TestDiscoveryFilter(t *testing.T) {
}

if !discoveryFilter.called {
t.Fatalf("Expecting true, got false")
t.Fatal("Expecting true, got false")
}

}
4 changes: 2 additions & 2 deletions pkg/client/common/discovery/dynamicdiscovery/chservice.go
Expand Up @@ -26,7 +26,7 @@ type ChannelService struct {

// NewChannelService creates a Discovery Service to query the list of member peers on a given channel.
func NewChannelService(ctx contextAPI.Client, channelID string, opts ...coptions.Opt) (*ChannelService, error) {
logger.Debugf("Creating new dynamic discovery service")
logger.Debug("Creating new dynamic discovery service")
s := &ChannelService{
channelID: channelID,
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (s *ChannelService) evaluate(ctx contextAPI.Client, responses []fabdiscover
for _, response := range responses {
endpoints, err := response.ForChannel(s.channelID).Peers()
if err != nil {
lastErr = errors.Wrapf(err, "error getting peers from discovery response")
lastErr = errors.Wrap(err, "error getting peers from discovery response")
logger.Warn(lastErr.Error())
continue
}
Expand Down
Expand Up @@ -43,6 +43,6 @@ func (p *LocalProvider) CreateLocalDiscoveryService(mspID string) (fab.Discovery

// Close will close the cache and all services contained by the cache.
func (p *LocalProvider) Close() {
logger.Debugf("Closing local provider cache")
logger.Debug("Closing local provider cache")
p.cache.Close()
}
10 changes: 5 additions & 5 deletions pkg/client/common/discovery/dynamicdiscovery/localservice.go
Expand Up @@ -24,7 +24,7 @@ type LocalService struct {

// newLocalService creates a Local Discovery Service to query the list of member peers in the local MSP.
func newLocalService(config fab.EndpointConfig, mspID string, opts ...coptions.Opt) *LocalService {
logger.Debugf("Creating new local discovery service")
logger.Debug("Creating new local discovery service")

s := &LocalService{mspID: mspID}
s.service = newService(config, s.queryPeers, opts...)
Expand All @@ -50,7 +50,7 @@ func (s *LocalService) localContext() contextAPI.Local {
}

func (s *LocalService) queryPeers() ([]fab.Peer, error) {
logger.Debugf("Refreshing local peers from discovery service...")
logger.Debug("Refreshing local peers from discovery service...")

ctx := s.localContext()
if ctx == nil {
Expand All @@ -68,16 +68,16 @@ func (s *LocalService) queryPeers() ([]fab.Peer, error) {
req := discclient.NewRequest().AddLocalPeersQuery()
responses, err := s.discoveryClient().Send(reqCtx, req, *target)
if err != nil {
return nil, errors.Wrapf(err, "error calling discover service send")
return nil, errors.Wrap(err, "error calling discover service send")
}
if len(responses) == 0 {
return nil, errors.Wrapf(err, "expecting 1 response from discover service send but got none")
return nil, errors.Wrap(err, "expecting 1 response from discover service send but got none")
}

response := responses[0]
endpoints, err := response.ForLocal().Peers()
if err != nil {
return nil, errors.Wrapf(err, "error getting peers from discovery response")
return nil, errors.Wrap(err, "error getting peers from discovery response")
}

return s.filterLocalMSP(asPeers(ctx, endpoints)), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/common/discovery/dynamicdiscovery/opts.go
Expand Up @@ -21,7 +21,7 @@ type options struct {
// peer cache is refreshed
func WithRefreshInterval(value time.Duration) coptions.Opt {
return func(p coptions.Params) {
logger.Debugf("Checking refreshIntervalSetter")
logger.Debug("Checking refreshIntervalSetter")
if setter, ok := p.(refreshIntervalSetter); ok {
setter.SetRefreshInterval(value)
}
Expand All @@ -31,7 +31,7 @@ func WithRefreshInterval(value time.Duration) coptions.Opt {
// WithResponseTimeout sets the Discover service response timeout
func WithResponseTimeout(value time.Duration) coptions.Opt {
return func(p coptions.Params) {
logger.Debugf("Checking responseTimeoutSetter")
logger.Debug("Checking responseTimeoutSetter")
if setter, ok := p.(responseTimeoutSetter); ok {
setter.SetResponseTimeout(value)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/common/discovery/dynamicdiscovery/service.go
Expand Up @@ -81,7 +81,7 @@ func (s *service) initialize(ctx contextAPI.Client) error {

discoveryClient, err := clientProvider(ctx)
if err != nil {
return errors.Wrapf(err, "error creating discover client")
return errors.Wrap(err, "error creating discover client")
}

logger.Debugf("Initializing with context: %#v", ctx)
Expand All @@ -92,7 +92,7 @@ func (s *service) initialize(ctx contextAPI.Client) error {

// Close stops the lazyref background refresh
func (s *service) Close() {
logger.Debugf("Closing peers ref...")
logger.Debug("Closing peers ref...")
s.peersRef.Close()
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/client/common/filter/endpoint_test.go
Expand Up @@ -24,7 +24,7 @@ func TestInvalidOpt(t *testing.T) {

peer := mocks.NewMockPeer("Peer1", "example.com")
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer")
t.Fatal("Should have accepted peer")
}

}
Expand All @@ -39,13 +39,13 @@ func TestChaincodeQueryFilter(t *testing.T) {
ef := NewEndpointFilter(channel, ChaincodeQuery)

if !ef.Accept(mocks.NewMockPeer("Peer1", "non-configured.com")) {
t.Fatalf("Should have accepted peer that is not configured")
t.Fatal("Should have accepted peer that is not configured")
}

// Configured peer
peer := mocks.NewMockPeer("Peer1", "example.com")
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer")
t.Fatal("Should have accepted peer")
}

channel, err = mocks.NewMockChannel("noEndpoints")
Expand All @@ -54,7 +54,7 @@ func TestChaincodeQueryFilter(t *testing.T) {
t.Fatalf("Failed to create mock channel: %s", err)
}
if ef.Accept(peer) {
t.Fatalf("Should NOT have accepted peer since peers chaincode query option is configured to false")
t.Fatal("Should NOT have accepted peer since peers chaincode query option is configured to false")
}

channel, err = mocks.NewMockChannel("noChannelPeers")
Expand All @@ -63,7 +63,7 @@ func TestChaincodeQueryFilter(t *testing.T) {
t.Fatalf("Failed to create mock channel: %s", err)
}
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer since no peers configured")
t.Fatal("Should have accepted peer since no peers configured")
}

}
Expand All @@ -79,7 +79,7 @@ func TestLedgerQueryFilter(t *testing.T) {

peer := mocks.NewMockPeer("Peer1", "example.com")
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer")
t.Fatal("Should have accepted peer")
}

}
Expand All @@ -95,7 +95,7 @@ func TestEndorsingPeerFilter(t *testing.T) {

peer := mocks.NewMockPeer("Peer1", "example.com")
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer")
t.Fatal("Should have accepted peer")
}

}
Expand All @@ -111,7 +111,7 @@ func TestEventSourceFilter(t *testing.T) {

peer := mocks.NewMockPeer("Peer1", "example.com")
if !ef.Accept(peer) {
t.Fatalf("Should have accepted peer")
t.Fatal("Should have accepted peer")
}

}
Expand Up @@ -223,7 +223,7 @@ func verify(t *testing.T, service fab.SelectionService, expectedPeerGroups []pgr
t.Fatalf("error getting endorsers: %s", err)
}
if !containsPeerGroup(expectedPeerGroups, peers) {
t.Fatalf("peer group %s is not one of the expected peer groups: %v", toString(peers), expectedPeerGroups)
t.Fatalf("peer group %s is not one of the expected peer groups: %+v", toString(peers), expectedPeerGroups)
}
}

Expand Down

0 comments on commit 81694dd

Please sign in to comment.