Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 7a65fa4

Browse files
committed
[FAB-11040] Merge negative integration tests
This change merges the negative integration tests including docker environments and scripts. Change-Id: I57f3348d7b67e728374d92500b2c9aa8ae3c59af Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent b10481b commit 7a65fa4

File tree

13 files changed

+56
-386
lines changed

13 files changed

+56
-386
lines changed

Makefile

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ FABRIC_SDK_DEPRECATED_UNITTEST ?= false
7676
# Code levels to exercise integration/e2e tests against (overridable)
7777
FABRIC_STABLE_INTTEST ?= true
7878
FABRIC_STABLE_PKCS11_INTTEST ?= false
79-
FABRIC_STABLE_REVOKED_INTTEST ?= false
80-
FABRIC_STABLE_EXPIRED_INTTEST ?= false
79+
FABRIC_STABLE_NEGATIVE_INTTEST ?= false
8180
FABRIC_PREV_INTTEST ?= false
8281
FABRIC_PRERELEASE_INTTEST ?= false
8382
FABRIC_DEVSTABLE_INTTEST ?= false
@@ -148,8 +147,7 @@ export FABRIC_SDKGO_DEPEND_INSTALL=true
148147
FABRIC_SDK_DEPRECATED_UNITTEST := false
149148
FABRIC_STABLE_INTTEST := true
150149
FABRIC_STABLE_PKCS11_INTTEST := true
151-
FABRIC_STABLE_REVOKED_INTTEST := true
152-
FABRIC_STABLE_EXPIRED_INTTEST := true
150+
FABRIC_STABLE_NEGATIVE_INTTEST := true
153151
FABRIC_PREV_INTTEST := true
154152
FABRIC_PRERELEASE_INTTEST := false
155153
FABRIC_DEVSTABLE_INTTEST := false
@@ -269,25 +267,11 @@ integration-tests-devstable: clean-tests depend-noforce populate-noforce
269267
TEST_CHANGED_ONLY=true FABRIC_FIXTURE_VERSION=v$(FABRIC_DEVSTABLE_VERSION_MINOR) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_DEVSTABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_DEVSTABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_DEV_REGISTRY) $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-nopkcs11-test.yaml up --force-recreate --abort-on-container-exit
270268
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_DEV_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "-f ./docker-compose.yaml -f ./docker-compose-nopkcs11-test.yaml"
271269

272-
.PHONY: integration-tests-stable-revoked
270+
.PHONY: integration-tests-stable-negative
273271
integration-tests-stable-revoked: clean-tests depend-noforce populate-noforce
274272
@cd $(FIXTURE_DOCKERENV_PATH) && \
275-
TEST_CHANGED_ONLY=true FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-revoked.yaml up --force-recreate --abort-on-container-exit
276-
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "-f ./docker-compose.yaml -f ./docker-compose-revoked.yaml"
277-
278-
.PHONY: integration-tests-stable-orderer-cert-expired
279-
integration-tests-stable-orderer-cert-expired: clean-tests depend-noforce populate-noforce
280-
@cd $(FIXTURE_DOCKERENV_PATH) && \
281-
TEST_CHANGED_ONLY=true FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-expired-orderer.yaml up --force-recreate --abort-on-container-exit
282-
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "-f ./docker-compose.yaml -f ./docker-compose-expired-orderer.yaml"
283-
284-
.PHONY: integration-tests-stable-peer-cert-expired
285-
integration-tests-stable-peer-cert-expired: clean-tests depend-noforce populate-noforce
286-
@cd $(FIXTURE_DOCKERENV_PATH) && \
287-
TEST_CHANGED_ONLY=true FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-expired-peer.yaml up --force-recreate --abort-on-container-exit
288-
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "-f ./docker-compose.yaml -f ./docker-compose-expired-peer.yaml"
289-
290-
273+
TEST_CHANGED_ONLY=true FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-negative.yaml up --force-recreate --abort-on-container-exit
274+
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "-f ./docker-compose.yaml -f ./docker-compose-negative.yaml"
291275

292276
.PHONY: integration-tests-stable-pkcs11
293277
integration-tests-stable-pkcs11: clean-tests depend-noforce populate-noforce build-softhsm2-image
@@ -319,18 +303,9 @@ ifeq ($(FABRIC_STABLE_PKCS11_INTTEST),true)
319303
@$(MAKE) -f $(MAKEFILE_THIS) clean-tests
320304
@FABRIC_SDKGO_SUBTARGET=true $(MAKE) -f $(MAKEFILE_THIS) integration-tests-stable-pkcs11
321305
endif
322-
ifeq ($(FABRIC_STABLE_REVOKED_INTTEST),true)
323-
@$(MAKE) -f $(MAKEFILE_THIS) clean-tests
324-
@FABRIC_SDKGO_SUBTARGET=true $(MAKE) -f $(MAKEFILE_THIS) integration-tests-stable-revoked
325-
endif
326-
327-
ifeq ($(FABRIC_STABLE_EXPIRED_INTTEST),true)
328-
@$(MAKE) -f $(MAKEFILE_THIS) clean-tests
329-
@FABRIC_SDKGO_SUBTARGET=true $(MAKE) -f $(MAKEFILE_THIS) integration-tests-stable-orderer-cert-expired
330-
endif
331-
ifeq ($(FABRIC_STABLE_EXPIRED_INTTEST),true)
306+
ifeq ($(FABRIC_STABLE_NEGATIVE_INTTEST),true)
332307
@$(MAKE) -f $(MAKEFILE_THIS) clean-tests
333-
@FABRIC_SDKGO_SUBTARGET=true $(MAKE) -f $(MAKEFILE_THIS) integration-tests-stable-peer-cert-expired
308+
@FABRIC_SDKGO_SUBTARGET=true $(MAKE) -f $(MAKEFILE_THIS) integration-tests-stable-negative
334309
endif
335310

336311
ifeq ($(FABRIC_PRERELEASE_INTTEST),true)

test/fixtures/dockerenv/docker-compose-expired-orderer.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/fixtures/dockerenv/docker-compose-expired-peer.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/fixtures/dockerenv/docker-compose-revoked.yaml renamed to test/fixtures/dockerenv/docker-compose-negative.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
- TEST_CHANGED_ONLY
2020
volumes:
2121
- ../../../:/opt/gopath/src/github.com/hyperledger/fabric-sdk-go
22-
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/revoked.sh
22+
command: /opt/gopath/src/github.com/hyperledger/fabric-sdk-go/test/scripts/negative.sh
2323
depends_on:
2424
- org1ca1
2525
- org2ca1

test/integration/base_test_setup.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ package integration
88

99
import (
1010
"fmt"
11+
"go/build"
1112
"os"
1213
"path"
14+
"path/filepath"
1315
"testing"
1416

1517
mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
@@ -142,14 +144,36 @@ func (setup *BaseSetupImpl) Initialize(sdk *fabsdk.FabricSDK) error {
142144
return nil
143145
}
144146

145-
// GetDeployPath ..
147+
// GetDeployPath returns the path to the chaincode fixtures
146148
func GetDeployPath() string {
147-
pwd, err := os.Getwd()
148-
if err != nil {
149-
panic(fmt.Sprintf("Getwd failed: %s", err))
150-
}
149+
const ccPath = "test/fixtures/testdata"
150+
return path.Join(goPath(), "src", metadata.Project, ccPath)
151+
}
152+
153+
// GetChannelConfigPath returns the path to the named channel config file
154+
func GetChannelConfigPath(filename string) string {
155+
return path.Join(goPath(), "src", metadata.Project, metadata.ChannelConfigPath, filename)
156+
}
157+
158+
// GetConfigPath returns the path to the named config fixture file
159+
func GetConfigPath(filename string) string {
160+
const configPath = "test/fixtures/config"
161+
return path.Join(goPath(), "src", metadata.Project, configPath, filename)
162+
}
163+
164+
// GetConfigOverridesPath returns the path to the named config override fixture file
165+
func GetConfigOverridesPath(filename string) string {
166+
const configPath = "test/fixtures/config/overrides"
167+
return path.Join(goPath(), "src", metadata.Project, configPath, "overrides", filename)
168+
}
169+
170+
// goPath returns the current GOPATH. If the system
171+
// has multiple GOPATHs then the first is used.
172+
func goPath() string {
173+
gpDefault := build.Default.GOPATH
174+
gps := filepath.SplitList(gpDefault)
151175

152-
return path.Join(pwd, "../../fixtures/testdata")
176+
return gps[0]
153177
}
154178

155179
// InstallAndInstantiateExampleCC install and instantiate using resource management client
@@ -226,7 +250,7 @@ func CreateChannelAndUpdateAnchorPeers(t *testing.T, sdk *fabsdk.FabricSDK, chan
226250

227251
req := resmgmt.SaveChannelRequest{
228252
ChannelID: channelID,
229-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, channelConfigFile),
253+
ChannelConfigPath: GetChannelConfigPath(channelConfigFile),
230254
SigningIdentities: signingIdentities,
231255
}
232256
_, err = chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
@@ -239,7 +263,7 @@ func CreateChannelAndUpdateAnchorPeers(t *testing.T, sdk *fabsdk.FabricSDK, chan
239263
for _, orgCtx := range orgsContext {
240264
req := resmgmt.SaveChannelRequest{
241265
ChannelID: channelID,
242-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, orgCtx.AnchorPeerConfigFile),
266+
ChannelConfigPath: GetChannelConfigPath(orgCtx.AnchorPeerConfigFile),
243267
SigningIdentities: []msp.SigningIdentity{orgCtx.SigningIdentity},
244268
}
245269
if _, err := orgCtx.ResMgmt.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com")); err != nil {

test/integration/expiredorderer/expired_certificate_test.go renamed to test/integration/negative/expiredorderer/expired_certificate_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package expiredorderer
88

99
import (
1010
"os"
11-
"path"
1211
"testing"
1312

1413
mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
@@ -18,14 +17,12 @@ import (
1817
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
1918
"google.golang.org/grpc/grpclog"
2019

21-
"github.com/hyperledger/fabric-sdk-go/test/integration"
22-
"github.com/hyperledger/fabric-sdk-go/test/metadata"
23-
2420
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
2521
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
2622
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
2723
"github.com/hyperledger/fabric-sdk-go/pkg/core/mocks"
2824
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
25+
"github.com/hyperledger/fabric-sdk-go/test/integration"
2926
"github.com/stretchr/testify/assert"
3027
)
3128

@@ -36,7 +33,7 @@ const (
3633
ordererOrgName = "ordererorg"
3734
org1AdminUser = "Admin"
3835
org2AdminUser = "Admin"
39-
configPath = "../../fixtures/config/config_test.yaml"
36+
configFilename = "config_test.yaml"
4037
expiredCertPath = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/ordererOrganizations/example.com/expiredtlsca/expired.pem"
4138
)
4239

@@ -92,7 +89,7 @@ func TestExpiredCert(t *testing.T) {
9289
}
9390

9491
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
95-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
92+
ChannelConfigPath: integration.GetChannelConfigPath("orgchannel.tx"),
9693
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
9794
_, err = chMgmtClient.SaveChannel(req)
9895
//error in GRPC log is ' Failed to dial orderer.example.com:7050: connection error: desc = "transport: authentication handshake failed: x509: certificate has expiredorderer or is not yet valid"; '
@@ -104,7 +101,7 @@ func TestExpiredCert(t *testing.T) {
104101

105102
func getConfigBackend(t *testing.T) core.ConfigProvider {
106103
return func() ([]core.ConfigBackend, error) {
107-
configBackends, err := config.FromFile(configPath)()
104+
configBackends, err := config.FromFile(integration.GetConfigPath(configFilename))()
108105
assert.Nil(t, err, "failed to read config backend from file, %s", err)
109106
backendMap := make(map[string]interface{})
110107

test/integration/expiredpeer/expired_certificate_test.go renamed to test/integration/negative/expiredpeer/expired_certificate_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package expiredpeer
88

99
import (
10-
"path"
1110
"testing"
1211

1312
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
@@ -20,7 +19,6 @@ import (
2019
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
2120

2221
"github.com/hyperledger/fabric-sdk-go/test/integration"
23-
"github.com/hyperledger/fabric-sdk-go/test/metadata"
2422

2523
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
2624
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
@@ -36,7 +34,7 @@ const (
3634
ordererOrgName = "ordererorg"
3735
org1AdminUser = "Admin"
3836
org2AdminUser = "Admin"
39-
configPath = "../../fixtures/config/config_test.yaml"
37+
configFilename = "config_test.yaml"
4038
expiredCertPath = "${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/expiredtlsca/expired.pem"
4139
)
4240

@@ -87,7 +85,7 @@ func TestExpiredPeersCert(t *testing.T) {
8785
}
8886

8987
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
90-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
88+
ChannelConfigPath: integration.GetConfigPath("orgchannel.tx"),
9189
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
9290
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
9391
require.Nil(t, err, "error should be nil")
@@ -110,7 +108,7 @@ func TestExpiredPeersCert(t *testing.T) {
110108
func getConfigBackend(t *testing.T) core.ConfigProvider {
111109

112110
return func() ([]core.ConfigBackend, error) {
113-
configBackends, err := config.FromFile(configPath)()
111+
configBackends, err := config.FromFile(integration.GetConfigPath(configFilename))()
114112
assert.Nil(t, err, "failed to read config backend from file", err)
115113
backendMap := make(map[string]interface{})
116114

test/integration/revoked/revoked_peer_test.go renamed to test/integration/negative/revoked/revoked_peer_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package revoked
88

99
import (
10-
"path"
1110
"strings"
1211
"testing"
1312

@@ -23,7 +22,6 @@ import (
2322
mspclient "github.com/hyperledger/fabric-sdk-go/pkg/client/msp"
2423
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
2524
"github.com/hyperledger/fabric-sdk-go/test/integration"
26-
"github.com/hyperledger/fabric-sdk-go/test/metadata"
2725

2826
"os"
2927

@@ -49,7 +47,7 @@ const (
4947
org2AdminUser = "Admin"
5048
org1User = "User1"
5149
channelID = "orgchannel"
52-
configPath = "../../fixtures/config/config_test.yaml"
50+
configFilename = "config_test.yaml"
5351
)
5452

5553
// SDK
@@ -186,7 +184,7 @@ func queryCC(org1ChannelClientContext contextAPI.ChannelProvider, t *testing.T)
186184
}
187185

188186
func createCC(t *testing.T, org1ResMgmt *resmgmt.Client, org2ResMgmt *resmgmt.Client) {
189-
ccPkg, err := packager.NewCCPackage("github.com/example_cc", "../../fixtures/testdata")
187+
ccPkg, err := packager.NewCCPackage("github.com/example_cc", integration.GetDeployPath())
190188
if err != nil {
191189
t.Fatal(err)
192190
}
@@ -224,7 +222,7 @@ func createCC(t *testing.T, org1ResMgmt *resmgmt.Client, org2ResMgmt *resmgmt.Cl
224222

225223
func createChannel(org1AdminUser msp.SigningIdentity, org2AdminUser msp.SigningIdentity, chMgmtClient *resmgmt.Client, t *testing.T) {
226224
req := resmgmt.SaveChannelRequest{ChannelID: "orgchannel",
227-
ChannelConfigPath: path.Join("../../../", metadata.ChannelConfigPath, "orgchannel.tx"),
225+
ChannelConfigPath: integration.GetChannelConfigPath("orgchannel.tx"),
228226
SigningIdentities: []msp.SigningIdentity{org1AdminUser, org2AdminUser}}
229227
txID, err := chMgmtClient.SaveChannel(req, resmgmt.WithRetry(retry.DefaultResMgmtOpts), resmgmt.WithOrdererEndpoint("orderer.example.com"))
230228
require.Nil(t, err, "error should be nil")
@@ -259,7 +257,7 @@ func loadOrgPeers(t *testing.T, ctxProvider contextAPI.ClientProvider) {
259257
func getConfigBackend() core.ConfigProvider {
260258

261259
return func() ([]core.ConfigBackend, error) {
262-
configBackends, err := config.FromFile(configPath)()
260+
configBackends, err := config.FromFile(integration.GetConfigPath(configFilename))()
263261
if err != nil {
264262
return nil, errors.Wrap(err, "failed to read config backend from file, %v")
265263
}

test/metadata/metadata.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ var ChannelConfigPath = "test/fixtures/fabric/v1.2/channel"
1212

1313
// CryptoConfigPath is the relative path to the generated crypto config directory
1414
var CryptoConfigPath = "test/fixtures/fabric/v1/crypto-config"
15+
16+
// Project is the Go project name relative to the Go Path
17+
var Project = "github.com/hyperledger/fabric-sdk-go"

0 commit comments

Comments
 (0)