Skip to content

Commit

Permalink
[FAB-9490] Integration: Use require instead of assert
Browse files Browse the repository at this point in the history
Change-Id: I32ff0cb3443ed6d6b461811ee850d1e4f275a20f
Signed-off-by: Sandra Vrtikapa <[email protected]>
  • Loading branch information
sandrask committed Apr 12, 2018
1 parent 2acb5d0 commit 66ac24e
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 60 deletions.
7 changes: 5 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions test/integration/e2e/end_to_end.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
Expand Down Expand Up @@ -84,8 +84,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "mychannel.tx"),
SigningIdentities: []msp.SigningIdentity{adminIdentity}}
txID, err := resMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, txID, "transaction ID should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

//prepare context
adminContext := sdk.Context(fabsdk.WithUser(orgAdmin), fabsdk.WithOrg(orgName))
Expand Down Expand Up @@ -123,8 +123,8 @@ func Run(t *testing.T, configOpt core.ConfigProvider, sdkOpts ...fabsdk.Option)
resmgmt.InstantiateCCRequest{Name: ccID, Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.WithRetry(retry.DefaultResMgmtOpts),
)
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp, "transaction response should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, resp, "transaction response should be populated")

// ************ Test setup complete ************** //

Expand Down
6 changes: 3 additions & 3 deletions test/integration/expiredpeer/expired_certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
Expand Down Expand Up @@ -78,8 +78,8 @@ func TestExpiredPeersCert(t *testing.T) {
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, txID, "transaction ID should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

// Org1 resource management client (Org1 is default org)
org1ResMgmt, err := resmgmt.New(org1AdminClientContext)
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fab/channel_ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -75,8 +75,8 @@ func TestLedgerQueries(t *testing.T) {

chaincodeID := integration.GenerateRandomID()
resp, err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), orgName, chaincodeID)
assert.Nil(t, err, "InstallAndInstantiateExampleCC return error")
assert.NotEmpty(t, resp, "instantiate response should be populated")
require.Nil(t, err, "InstallAndInstantiateExampleCC return error")
require.NotEmpty(t, resp, "instantiate response should be populated")

//prepare required contexts

Expand Down
4 changes: 2 additions & 2 deletions test/integration/fab/eventclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-sdk-go/test/integration"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ func testEventService(t *testing.T, testSetup *integration.BaseSetupImpl, sdk *f
defer cancel()

peers, err := getProposalProcessors(sdk, "Admin", testSetup.OrgID, testSetup.Targets)
assert.Nil(t, err, "creating peers failed")
require.Nil(t, err, "creating peers failed")

tpResponses, prop, err := createAndSendTransactionProposal(
transactor,
Expand Down
6 changes: 3 additions & 3 deletions test/integration/fab/install_chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -75,7 +75,7 @@ func testChaincodeInstallUsingChaincodePath(t *testing.T, sdk *fabsdk.FabricSDK,
defer cancel()

peers, err := getProposalProcessors(sdk, "Admin", testSetup.OrgID, testSetup.Targets)
assert.Nil(t, err, "creating peers failed")
require.Nil(t, err, "creating peers failed")

if err := installCC(reqCtx, chainCodeName, chainCodePath, chainCodeVersion, ccPkg, peers); err != nil {
t.Fatalf("installCC return error: %v", err)
Expand Down Expand Up @@ -126,7 +126,7 @@ func testChaincodeInstallUsingChaincodePackage(t *testing.T, sdk *fabsdk.FabricS
defer cancel()

peers, err := getProposalProcessors(sdk, "Admin", testSetup.OrgID, testSetup.Targets)
assert.Nil(t, err, "creating peers failed")
require.Nil(t, err, "creating peers failed")

err = installCC(reqCtx, "install", "github.com/example_cc_pkg", chainCodeVersion, ccPkg, peers)

Expand Down
4 changes: 2 additions & 2 deletions test/integration/fab/resource_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestChannelQueries(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func TestChannelQueries(t *testing.T) {
defer cancel()

peers, err := getProposalProcessors(sdk, "Admin", testSetup.OrgID, testSetup.Targets[:1])
assert.Nil(t, err, "creating peers failed")
require.Nil(t, err, "creating peers failed")

testQueryChannels(t, reqCtx, peers[0])

Expand Down
4 changes: 2 additions & 2 deletions test/integration/fab/transient_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestTransient ...
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestTransient(t *testing.T) {
defer cancel()

peers, err := getProposalProcessors(sdk, "Admin", testSetup.OrgID, testSetup.Targets[:1])
assert.Nil(t, err, "creating peers failed")
require.Nil(t, err, "creating peers failed")

transactionProposalResponse, _, err := createAndSendTransactionProposal(transactor, chaincodeID, fcn, integration.ExampleCCTxArgs(), peers, transientDataMap)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/msp/check_cert_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/attrmgr"
"github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func checkCertAttributes(t *testing.T, certBytes []byte, expected []msp.Attribute) {
Expand All @@ -38,9 +38,9 @@ func checkCertAttributes(t *testing.T, certBytes []byte, expected []msp.Attribut
}
for _, a := range expected {
v, ok, err := attrs.Value(a.Name)
assert.NoError(t, err)
assert.True(t, attrs.Contains(a.Name), "does not contain attribute '%s'", a.Name)
assert.True(t, ok, "attribute '%s' was not found", a.Name)
assert.True(t, v == a.Value, "incorrect value for '%s'; expected '%s' but found '%s'", a.Name, a.Value, v)
require.NoError(t, err)
require.True(t, attrs.Contains(a.Name), "does not contain attribute '%s'", a.Name)
require.True(t, ok, "attribute '%s' was not found", a.Name)
require.True(t, v == a.Value, "incorrect value for '%s'; expected '%s' but found '%s'", a.Name, a.Value, v)
}
}
26 changes: 13 additions & 13 deletions test/integration/orgs/multiple_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
packager "github.com/hyperledger/fabric-sdk-go/pkg/fab/ccpackager/gopackager"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
Expand Down Expand Up @@ -109,8 +109,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, txID, "transaction ID should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

// Org1 resource management client (Org1 is default org)
org1ResMgmt, err := resmgmt.New(org1AdminClientContext)
Expand Down Expand Up @@ -159,8 +159,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {

// Org1 resource manager will instantiate 'example_cc' on 'orgchannel'
instantiateResp, err := org1ResMgmt.InstantiateCC("orgchannel", resmgmt.InstantiateCCRequest{Name: "exampleCC", Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy}, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, instantiateResp, "transaction response should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, instantiateResp, "transaction response should be populated")

// Verify that example CC is instantiated on Org1 peer
chaincodeQueryResponse, err := org1ResMgmt.QueryInstantiatedChaincodes("orgchannel", resmgmt.WithRetry(retry.DefaultResMgmtOpts))
Expand Down Expand Up @@ -194,15 +194,15 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {
// Call with a dummy function and expect a fail with multiple errors
response, err := chClientOrg1User.Query(channel.Request{ChaincodeID: "exampleCC", Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCQueryArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
assert.Error(t, err, "Should have failed with dummy function")
require.Error(t, err, "Should have failed with dummy function")
s, ok := status.FromError(err)
assert.True(t, ok, "expected status error")
assert.Equal(t, s.Code, int32(status.MultipleErrors))
require.True(t, ok, "expected status error")
require.Equal(t, s.Code, int32(status.MultipleErrors))
for _, err := range err.(multi.Errors) {
s, ok := status.FromError(err)
assert.True(t, ok, "expected status error")
assert.EqualValues(t, int32(500), s.Code)
assert.Equal(t, status.ChaincodeStatus, s.Group)
require.True(t, ok, "expected status error")
require.EqualValues(t, int32(500), s.Code)
require.Equal(t, status.ChaincodeStatus, s.Group)
}

// Org1 user queries initial value on both peers
Expand Down Expand Up @@ -323,8 +323,8 @@ func testWithOrg1(t *testing.T, sdk *fabsdk.FabricSDK) int {

// Org1 resource manager will instantiate 'example_cc' version 1 on 'orgchannel'
upgradeResp, err := org1ResMgmt.UpgradeCC("orgchannel", resmgmt.UpgradeCCRequest{Name: "exampleCC", Path: "github.com/example_cc", Version: "1", Args: integration.ExampleCCUpgradeArgs(), Policy: org1Andorg2Policy})
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, upgradeResp, "transaction response should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, upgradeResp, "transaction response should be populated")

// Org2 user moves funds on org2 peer (cc policy fails since both Org1 and Org2 peers should participate)
response, err = chClientOrg2User.Execute(channel.Request{ChaincodeID: "exampleCC", Fcn: "invoke", Args: integration.ExampleCCTxArgs()}, channel.WithTargets(orgTestPeer1),
Expand Down
10 changes: 5 additions & 5 deletions test/integration/revoked/revoked_peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
"github.com/hyperledger/fabric-sdk-go/pkg/core/mocks"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -91,8 +91,8 @@ func TestRevokedPeer(t *testing.T) {
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, txID, "transaction ID should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, txID, "transaction ID should be populated")

// Org1 resource management client (Org1 is default org)
org1ResMgmt, err := resmgmt.New(org1AdminClientContext)
Expand Down Expand Up @@ -143,8 +143,8 @@ func TestRevokedPeer(t *testing.T) {
resp, err := org1ResMgmt.InstantiateCC("orgchannel",
resmgmt.InstantiateCCRequest{Name: "exampleCC", Path: "github.com/example_cc", Version: "0", Args: integration.ExampleCCInitArgs(), Policy: ccPolicy},
resmgmt.WithTargetURLs("peer0.org1.example.com"))
assert.Nil(t, err, "error should be nil")
assert.NotEmpty(t, resp, "transaction response should be populated")
require.Nil(t, err, "error should be nil")
require.NotEmpty(t, resp, "transaction response should be populated")

// Load specific targets for move funds test - one of the
//targets has its certificate revoked
Expand Down
12 changes: 6 additions & 6 deletions test/integration/sdk/channel_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke"
Expand Down Expand Up @@ -297,12 +297,12 @@ func testChaincodeError(ccID string, client *channel.Client, t *testing.T) {
// Try calling unknown function call and expect an error
_, err := client.Execute(channel.Request{ChaincodeID: ccID, Fcn: "DUMMY_FUNCTION", Args: integration.ExampleCCTxArgs()},
channel.WithRetry(retry.DefaultChClientOpts))
assert.Error(t, err)
require.Error(t, err)
s, ok := status.FromError(err)
assert.True(t, ok, "expected status error")
assert.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
assert.Equal(t, int32(500), s.Code)
assert.Equal(t, "Unknown function call", s.Message)
require.True(t, ok, "expected status error")
require.EqualValues(t, status.ChaincodeStatus, s.Group, "expected ChaincodeStatus")
require.Equal(t, int32(500), s.Code)
require.Equal(t, "Unknown function call", s.Message)
}

func TestNoEndpoints(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/sdk/channel_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/msp"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestChannelConfig(t *testing.T) {
Expand Down Expand Up @@ -188,10 +188,10 @@ func setupOrderer(t *testing.T, endPointConfig fab.EndpointConfig, address strin

//Get orderer config by orderer address
oCfg, err := endPointConfig.OrdererConfig(resolveOrdererAddress(address))
assert.Nil(t, err)
require.Nil(t, err)

o, err := orderer.New(endPointConfig, orderer.FromOrdererConfig(oCfg))
assert.Nil(t, err)
require.Nil(t, err)

return o
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/sdk/custom_cryptosuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
"github.com/hyperledger/fabric-sdk-go/test/integration"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const samplekey = "sample-key"
Expand Down Expand Up @@ -51,8 +51,8 @@ func customCryptoSuiteInit(t *testing.T) (*integration.BaseSetupImpl, string) {

chaincodeID := integration.GenerateRandomID()
resp, err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chaincodeID)
assert.Nil(t, err, "InstallAndInstantiateExampleCC return error")
assert.NotEmpty(t, resp, "instantiate response should be populated")
require.Nil(t, err, "InstallAndInstantiateExampleCC return error")
require.NotEmpty(t, resp, "instantiate response should be populated")

return testSetup, chaincodeID
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/sdk/sdk_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
selection "github.com/hyperledger/fabric-sdk-go/pkg/client/common/selection/dynamicselection"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDynamicSelection(t *testing.T) {
Expand Down Expand Up @@ -55,8 +55,8 @@ func TestDynamicSelection(t *testing.T) {

chainCodeID := integration.GenerateRandomID()
resp, err := integration.InstallAndInstantiateExampleCC(sdk, fabsdk.WithUser("Admin"), testSetup.OrgID, chainCodeID)
assert.Nil(t, err, "InstallAndInstantiateExampleCC return error")
assert.NotEmpty(t, resp, "instantiate response should be populated")
require.Nil(t, err, "InstallAndInstantiateExampleCC return error")
require.NotEmpty(t, resp, "instantiate response should be populated")

//prepare contexts
org1ChannelClientContext := sdk.ChannelContext(testSetup.ChannelID, fabsdk.WithUser(org1User), fabsdk.WithOrg(org1Name))
Expand Down

0 comments on commit 66ac24e

Please sign in to comment.