Skip to content

Commit

Permalink
[FAB-6343] Change Print to Log
Browse files Browse the repository at this point in the history
Change-Id: I36c105b753aea60f6e01e3e94ac971dfcb14393e
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Sep 30, 2017
1 parent 2fb9484 commit c299d70
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 89 deletions.
16 changes: 8 additions & 8 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func TestMultipleVipers(t *testing.T) {
viper.SetConfigFile("./test.yaml")
err := viper.ReadInConfig()
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}
testValue1 := viper.GetString("test.testkey")
// Read initial value from test.yaml
Expand All @@ -506,18 +506,18 @@ func TestMultipleVipers(t *testing.T) {
// initialize go sdk
_, err = InitConfig("../../test/fixtures/config/config_test.yaml")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

// Make sure initial value is unaffected
testValue2 := viper.GetString("test.testkey")
if testValue2 != "testvalue" {
t.Fatalf("Expected testvalue after config initialization")
t.Logf("Expected testvalue after config initialization")
}
// Make sure Go SDK config is unaffected
testValue3 := myViper.GetBool("client.BCCSP.security.softVerify")
if testValue3 != true {
t.Fatalf("Expected existing config value to remain unchanged")
t.Logf("Expected existing config value to remain unchanged")
}
}

Expand All @@ -531,12 +531,12 @@ func TestEnvironmentVariablesDefaultCmdRoot(t *testing.T) {
defer os.Unsetenv("FABRIC_SDK_ENV_TEST")

if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

_, err = InitConfig("../../test/fixtures/config/config_test.yaml")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

testValue = myViper.GetString("env.test")
Expand All @@ -555,12 +555,12 @@ func TestEnvironmentVariablesSpecificCmdRoot(t *testing.T) {
defer os.Unsetenv("TEST_ROOT_ENV_TEST")

if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

_, err = InitConfigWithCmdRoot("../../test/fixtures/config/config_test.yaml", "test_root")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

testValue = myViper.GetString("env.test")
Expand Down
5 changes: 4 additions & 1 deletion pkg/fabric-ca-client/mocks/mockfabriccaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
cfsslapi "github.com/cloudflare/cfssl/api"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")

var ecert = `-----BEGIN CERTIFICATE-----
MIICEjCCAbigAwIBAgIQPjb63mDL4e062MPjtcA1CDAKBggqhkjOPQQDAjBgMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
Expand Down Expand Up @@ -66,7 +69,7 @@ func StartFabricCAMockServer(address string) error {
if err != nil {
return fmt.Errorf("HTTP Server: Failed to start %v ", err.Error())
}
fmt.Println("HTTP Server started on :" + address)
logger.Infof("HTTP Server started on %s", address)
return nil

}
Expand Down
6 changes: 3 additions & 3 deletions pkg/fabric-client/channel/txnproposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestJoinChannel(t *testing.T) {
genesisBlockReqeust := &fab.GenesisBlockRequest{
TxnID: txid,
}
fmt.Printf("TxnID: %v", txid)
t.Logf("TxnID: %v", txid)

genesisBlock, err := channel.GenesisBlock(genesisBlockReqeust)
if err == nil {
Expand Down Expand Up @@ -266,10 +266,10 @@ func startEndorserServer(t *testing.T, grpcServer *grpc.Server) (*mocks.MockEndo
endorserServer := &mocks.MockEndorserServer{}
pb.RegisterEndorserServer(grpcServer, endorserServer)
if err != nil {
fmt.Printf("Error starting test server %s", err)
t.Logf("Error starting test server %s", err)
t.FailNow()
}
fmt.Printf("Starting test server on %s\n", addr)
t.Logf("Starting test server on %s\n", addr)
go grpcServer.Serve(lis)
return endorserServer, addr
}
5 changes: 4 additions & 1 deletion pkg/fabric-client/credentialmgr/credentialmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import (
"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
fabricCaUtil "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
)

var logger = logging.NewLogger("fabric_sdk_go")

// CredentialManager is used for retriving user's signing identity (ecert + private key)
type CredentialManager struct {
orgName string
Expand Down Expand Up @@ -109,7 +112,7 @@ func getFirstPathFromDir(dir string) (string, error) {
}

fullName := filepath.Join(dir, string(filepath.Separator), p.Name())
fmt.Printf("Reading file %s\n", fullName)
logger.Debugf("Reading file %s\n", fullName)
}

for _, f := range files {
Expand Down
5 changes: 2 additions & 3 deletions pkg/fabric-client/credentialmgr/credentialmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package credentialmgr

import (
"fmt"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/config"
Expand All @@ -18,7 +17,7 @@ func TestCredentialManager(t *testing.T) {

config, err := config.InitConfig("../../../test/fixtures/config/config_test.yaml")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

credentialMgr, err := NewCredentialManager("Org1", config, &fcmocks.MockCryptoSuite{})
Expand Down Expand Up @@ -47,7 +46,7 @@ func TestInvalidOrgCredentialManager(t *testing.T) {

config, err := config.InitConfig("../../../test/fixtures/config/config_test.yaml")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

// Invalid Org
Expand Down
2 changes: 1 addition & 1 deletion pkg/fabric-client/events/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (ec *eventsClient) RegisterAsync(ies []*ehpb.Interest) error {
Creator: creator,
}
if err = ec.send(emsg); err != nil {
fmt.Printf("error on Register send %s\n", err)
logger.Errorf("error on Register send %s\n", err)
}
return err
}
Expand Down
34 changes: 20 additions & 14 deletions pkg/fabric-client/events/eventhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sync/atomic"
"testing"

"fmt"

"time"

"reflect"
Expand All @@ -35,7 +33,7 @@ func TestDeadlock(t *testing.T) {
return
}

fmt.Printf("EventHub Concurrency test\n")
t.Log("EventHub Concurrency test")

client := clientFactory.clients[0]
if client == nil {
Expand Down Expand Up @@ -101,13 +99,13 @@ func TestDeadlock(t *testing.T) {
if txCompletion.numDone() != eventsSent {
t.Errorf("Sent %d Tx events but received %d - could indicate a deadlock", eventsSent, txCompletion.numDone())
} else {
fmt.Printf("Received all %d TX events.\n", txCompletion.numDone())
t.Logf("Received all %d TX events", txCompletion.numDone())
}

if ccCompletion.numDone() != eventsSent {
t.Errorf("Sent %d CC events but received %d - could indicate a deadlock", eventsSent, ccCompletion.numDone())
} else {
fmt.Printf("Received all %d CC events.\n", ccCompletion.numDone())
t.Logf("Received all %d CC events", ccCompletion.numDone())
}
}

Expand All @@ -120,7 +118,7 @@ func TestChaincodeEvent(t *testing.T) {
return
}

fmt.Printf("EventHub Chaincode event test\n")
t.Log("EventHub Chaincode event test")

client := clientFactory.clients[0]
if client == nil {
Expand Down Expand Up @@ -305,20 +303,22 @@ func TestRegisterBlockEvent(t *testing.T) {
t.Fatalf("Registered callback is not txCallback")
}

eventHub.RegisterBlockEvent(testCallback)
w := &callbackWrapper{t}

eventHub.RegisterBlockEvent(w.testCallback)

if len(eventHub.blockRegistrants) != 2 {
t.Fatalf("Failed to add test callback for block event")
}

f1 = reflect.ValueOf(testCallback)
f1 = reflect.ValueOf(w.testCallback)
f2 = reflect.ValueOf(eventHub.blockRegistrants[1])

if f1.Pointer() != f2.Pointer() {
t.Fatalf("Registered callback is not testCallback")
}

eventHub.UnregisterBlockEvent(testCallback)
eventHub.UnregisterBlockEvent(w.testCallback)

if len(eventHub.interestedEvents) != 1 || len(eventHub.blockRegistrants) != 1 {
t.Fatalf("Failed to unregister testCallback")
Expand All @@ -332,9 +332,13 @@ func TestRegisterBlockEvent(t *testing.T) {

}

type callbackWrapper struct {
t *testing.T
}

// private test callback to be executed on block event
func testCallback(block *common.Block) {
fmt.Println("testCallback called on block")
func (w *callbackWrapper) testCallback(block *common.Block) {
w.t.Log("testCallback called on block")
}

func TestRegisterChaincodeEvent(t *testing.T) {
Expand All @@ -348,7 +352,9 @@ func TestRegisterChaincodeEvent(t *testing.T) {
t.Fatalf("Transaction callback should be registered by default")
}

cbe := eventHub.RegisterChaincodeEvent("testCC", "eventID", testChaincodeCallback)
w := &callbackWrapper{t}

cbe := eventHub.RegisterChaincodeEvent("testCC", "eventID", w.testChaincodeCallback)

if len(eventHub.interestedEvents) != 2 {
t.Fatalf("Failed to register interest for CC event")
Expand Down Expand Up @@ -379,8 +385,8 @@ func TestRegisterChaincodeEvent(t *testing.T) {
}

// private test callback to be executed on chaincode event
func testChaincodeCallback(ce *fab.ChaincodeEvent) {
fmt.Printf("Received CC event: %v\n", ce)
func (w *callbackWrapper) testChaincodeCallback(ce *fab.ChaincodeEvent) {
w.t.Logf("Received CC event: %v", ce)
}

func TestDisconnect(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fabric-client/events/eventmocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (b *MockCCBlockEventBuilder) buildTransactionsFilterMetaDataBytes() []byte
}

func (b *MockCCBlockEventBuilder) buildPayload() *common.Payload {
fmt.Printf("MockCCBlockEventBuilder.buildPayload\n")
logger.Debug("MockCCBlockEventBuilder.buildPayload")
return &common.Payload{
Header: &common.Header{
ChannelHeader: internal.MarshalOrPanic(b.buildChannelHeader()),
Expand Down
10 changes: 5 additions & 5 deletions pkg/fabric-client/orderer/orderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestSendDeliver(t *testing.T) {
case block := <-blocks:
t.Fatalf("This usecase was not supposed to receive blocks : %#v", block)
case err := <-errors:
fmt.Printf("There is an error as expected : %s \n", err)
t.Logf("There is an error as expected : %s", err)
case <-time.After(time.Second * 5):
t.Fatalf("Did not receive error from SendDeliver")
}
Expand All @@ -203,10 +203,10 @@ func startMockServer(t *testing.T, grpcServer *grpc.Server) (*mocks.MockBroadcas
broadcastServer := new(mocks.MockBroadcastServer)
ab.RegisterAtomicBroadcastServer(grpcServer, broadcastServer)
if err != nil {
fmt.Printf("Error starting test server %s", err)
t.Logf("Error starting test server %s", err)
t.FailNow()
}
fmt.Printf("Starting test server on %s\n", addr)
t.Logf("Starting test server on %s", addr)
go grpcServer.Serve(lis)

return broadcastServer, addr
Expand All @@ -218,10 +218,10 @@ func startCustomizedMockServer(t *testing.T, serverURL string, grpcServer *grpc.

ab.RegisterAtomicBroadcastServer(grpcServer, broadcastServer)
if err != nil {
fmt.Printf("Error starting test server %s", err)
t.Logf("Error starting test server %s", err)
t.FailNow()
}
fmt.Printf("Starting test customized server on %s\n", addr)
t.Logf("Starting test customized server on %s\n", addr)
go grpcServer.Serve(lis)

return addr
Expand Down
4 changes: 2 additions & 2 deletions pkg/fabric-client/peer/peerendorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ func startEndorserServer(t *testing.T, grpcServer *grpc.Server) (*mocks.MockEndo
endorserServer := &mocks.MockEndorserServer{}
pb.RegisterEndorserServer(grpcServer, endorserServer)
if err != nil {
fmt.Printf("Error starting test server %s", err)
t.Logf("Error starting test server %s", err)
t.FailNow()
}
fmt.Printf("Starting test server (endorser server in peerendorser_test) on %s\n", addr)
t.Logf("Starting test server (endorser server in peerendorser_test) on %s", addr)
go grpcServer.Serve(lis)
return endorserServer, addr
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/fabric-txn/discovery/staticdiscovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package discovery

import (
"fmt"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/config"
Expand All @@ -29,7 +28,7 @@ func TestDiscovery(t *testing.T) {

config, err := config.InitConfig("../../../test/fixtures/config/config_test.yaml")
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

discoveryProvider, err := NewDiscoveryProvider(config)
Expand Down
Loading

0 comments on commit c299d70

Please sign in to comment.