Skip to content

Commit

Permalink
[FAB-7488] Fix integration tests outside docker
Browse files Browse the repository at this point in the history
This patch fixes the port exposure in fixtures and
the SDK test config. It also enables new make targets
for easier local testing and updates the README.

Change-Id: I17d6490692099691d14c61f63ad529a9ddf27075
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Dec 17, 2017
1 parent dafcfbc commit 9a9856d
Show file tree
Hide file tree
Showing 47 changed files with 105 additions and 48 deletions.
44 changes: 41 additions & 3 deletions Makefile
Expand Up @@ -82,13 +82,15 @@ FABRIC_STABLE_CODELEVEL_TAG := stable
FABRIC_PREV_CODELEVEL_TAG := prev
FABRIC_PRERELEASE_CODELEVEL_TAG := prerelease
FABRIC_DEVSTABLE_CODELEVEL_TAG := devstable
FABRIC_CODELEVEL_TAG ?= $(FABRIC_STABLE_CODELEVEL_TAG)

# Code level version targets
FABRIC_STABLE_CODELEVEL_VER := v$(FABRIC_STABLE_VERSION_MINOR)
FABRIC_PREV_CODELEVEL_VER := v$(FABRIC_PREV_VERSION)
FABRIC_PRERELEASE_CODELEVEL_VER := v$(FABRIC_PRERELEASE_VERSION)
FABRIC_DEVSTABLE_CODELEVEL_VER := v$(FABRIC_DEVSTABLE_VERSION_MINOR)
FABRIC_CODELEVEL_VER ?= v$(FABRIC_STABLE_CODELEVEL_VER)
FABRIC_CODELEVEL_VER ?= $(FABRIC_STABLE_CODELEVEL_VER)
FABRIC_CRYPTOCONFIG_VER ?= v$(FABRIC_STABLE_VERSION_MAJOR)

# Code level to exercise during unit tests
FABRIC_CODELEVEL_UNITTEST_TAG ?= $(FABRIC_DEVSTABLE_CODELEVEL_TAG)
Expand Down Expand Up @@ -268,6 +270,39 @@ ifeq ($(FABRIC_PREV_INTTEST),true)
endif
@$(MAKE) -f $(MAKEFILE_THIS) clean

.PHONY: integration-tests-local
integration-tests-local: temp-clean depend populate
FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_CODELEVEL_TAG) $(TEST_SCRIPTS_PATH)/integration.sh

.PHONY: dockerenv-prev-up
dockerenv-prev-up: clean
@cd $(FIXTURE_DOCKERENV_PATH) && \
FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_PREV_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_PREV_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY)/ $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml up --force-recreate

.PHONY: dockerenv-stable-up
dockerenv-stable-up: clean
@cd $(FIXTURE_DOCKERENV_PATH) && \
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 up --force-recreate

.PHONY: dockerenv-prerelease-up
dockerenv-prerelease-up: clean
@cd $(FIXTURE_DOCKERENV_PATH) && \
FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_PRERELEASE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_PRERELEASE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY)/ $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml up --force-recreate

.PHONY: dockerenv-devstable-up
dockerenv-devstable-up: clean
@. $(FIXTURE_DOCKERENV_PATH)/devstable-env.sh && \
$(FABRIC_DEV_REGISTRY_PRE_CMD) && \
cd $(FIXTURE_DOCKERENV_PATH) && \
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 up --force-recreate

.PHONY: dockerenv-latest-up
dockerenv-latest-up: clean
@. $(FIXTURE_DOCKERENV_PATH)/devstable-env.sh && \
. $(FIXTURE_DOCKERENV_PATH)/latest-env.sh && \
cd $(FIXTURE_DOCKERENV_PATH) && \
FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_DEVSTABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_DEVSTABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY="" $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml up --force-recreate

.PHONY: mock-gen
mock-gen:
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apitxn ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apitxn/mocks/mockapitxn.gen.go
Expand Down Expand Up @@ -340,9 +375,12 @@ populate-clean:
rm -Rf vendor

.PHONY: clean
clean:
-$(GO_CMD) clean
temp-clean:
-rm -Rf /tmp/enroll_user /tmp/msp /tmp/keyvaluestore /tmp/hfc-kvs /tmp/state
-rm -f integration-report.xml report.xml

.PHONY: clean
clean: temp-clean
-$(GO_CMD) clean
-FIXTURE_PROJECT_NAME=$(FIXTURE_PROJECT_NAME) DOCKER_REMOVE_FORCE=$(FIXTURE_DOCKER_REMOVE_FORCE) $(TEST_SCRIPTS_PATH)/clean_integration.sh

62 changes: 35 additions & 27 deletions README.md
Expand Up @@ -112,9 +112,14 @@ go test

You need:

- A working fabric and fabric-ca set up. It is recommended that you use the docker-compose file provided in `test/fixtures`. It is also recommended that you use the default .env settings provided in `test/fixtures`. See steps below.
- A working fabric and fabric-ca set up. It is recommended that you use the docker-compose file provided in `test/fixtures/dockerenv`. It is also recommended that you use the default .env settings provided in `test/fixtures/dockerenv`. See steps below.
- Customized settings in the `test/fixtures/config/config_test.yaml` in case your Hyperledger Fabric network is not running on `localhost` or is using different ports.

#### Enable local hostnames

You will need to set the following hosts to 127.0.0.1 (typically in /etc/hosts):
ca_peerOrg1 ca_peerOrg2 peer0.org1.example.com peer1.org1.example.com peer0.org2.example.com peer1.org2.example.com orderer.example.com

#### Testing with Fabric Images at Docker Hub

The test suite defaults to the latest compatible tag of fabric images at Docker Hub.
Expand All @@ -124,22 +129,40 @@ The following commands starts Fabric:
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/

# Clean previous test run artifacts
make clean
# Start fabric (stable tag)
make dockerenv-stable-up

# Start fabric
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
docker-compose up --force-recreate
# Or more generally, start fabric at a different code level (prev, stable, prerelease, devstable)
# make dockerenv-[CODELEVEL]-up
```

#### Running Integration Tests

Fabric should now be running. In a different shell, run integration tests

```bash
# In the Fabric SDK integration tests directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
go test
# In the Fabric SDK Go directory
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go

# Use script to setup parameters for integration tests and execute them
make integration-tests-local

# Or more generally, run integration tests at a different code level (prev, stable, prerelease, devstable)
# and fixture target version
# FABRIC_CODELEVEL_VER=[VER] FABRIC_CODELEVEL_TAG=[CODELEVEL] make integration-tests-local
```


```bash
# It is also possible to run integration tests using go test directly. For example:
#cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/
#go test

#cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/integration/orgs
#go test

# You should review test/scripts/integration.sh for options and details.
# Note: you should generally prefer the scripted version to setup parameters for you.
```

#### Using default config
Expand All @@ -155,26 +178,11 @@ Note that this default config is used only if environment configuration yaml fil

#### Testing with Local Build of Fabric (Advanced)

Alternatively you can build and run Fabric on your own box using the following commands:
Alternatively you can use a local build of Fabric using the following commands:

```bash
# Build fabric:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric
cd $GOPATH/src/github.com/hyperledger/fabric/
git checkout v1.0.4
make docker

# Build fabric-ca:
cd $GOPATH/src/github.com/hyperledger/
git clone https://github.com/hyperledger/fabric-ca
cd $GOPATH/src/github.com/hyperledger/fabric-ca/
git checkout v1.0.4
make docker

# Start fabric - latest-env.sh overrides the default docker tags in .env
cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/test/fixtures/
(source latest-env.sh && docker-compose up --force-recreate)
# Start fabric (devstable codelevel with latest docker tags)
make dockerenv-latest-up
```

## License
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/config/config_pkcs11_test.yaml
Expand Up @@ -257,8 +257,8 @@ peers:
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

peer0.org2.example.com:
url: grpcs://peer0.org2.example.com:7051
eventUrl: grpcs://peer0.org2.example.com:7053
url: grpcs://peer0.org2.example.com:8051
eventUrl: grpcs://peer0.org2.example.com:8053
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
tlsCACerts:
Expand Down Expand Up @@ -292,7 +292,7 @@ certificateAuthorities:
# [Optional] The optional name of the CA.
caName: ca-org1
ca-org2:
url: https://ca_peerOrg2:7054
url: https://ca_peerOrg2:8054
# the properties specified under this object are passed to the 'http' client verbatim when
# making the request to the Fabric-CA server
httpOptions:
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/config/config_test.yaml
Expand Up @@ -262,8 +262,8 @@ peers:
path: ${GOPATH}/src/github.com/hyperledger/fabric-sdk-go/${CRYPTOCONFIG_FIXTURES_PATH}/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem

peer0.org2.example.com:
url: grpcs://peer0.org2.example.com:7051
eventUrl: grpcs://peer0.org2.example.com:7053
url: grpcs://peer0.org2.example.com:8051
eventUrl: grpcs://peer0.org2.example.com:8053
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
tlsCACerts:
Expand Down Expand Up @@ -297,7 +297,7 @@ certificateAuthorities:
# [Optional] The optional name of the CA.
caName: ca-org1
ca-org2:
url: https://ca_peerOrg2:7054
url: https://ca_peerOrg2:8054
# the properties specified under this object are passed to the 'http' client verbatim when
# making the request to the Fabric-CA server
httpOptions:
Expand Down
26 changes: 18 additions & 8 deletions test/fixtures/dockerenv/docker-compose.yaml
Expand Up @@ -44,8 +44,8 @@ services:
logging:
driver: none
ports:
- "8054:7054"
command: sh -c 'fabric-ca-server start -b admin:adminpw -d'
- "8054:8054"
command: sh -c 'fabric-ca-server start -b admin:adminpw -d -p 8054'
volumes:
- ../fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/ca/:/etc/hyperledger/fabric-ca-server-config/
- ../fabricca/tls/certs/server:/etc/hyperledger/fabric-ca-server-config/tls
Expand Down Expand Up @@ -92,6 +92,8 @@ services:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer0.org1.example.com
- CORE_LOGGING_PEER=debug
# - CORE_LOGGING_GRPC=debug
# - CORE_LOGGING_GOSSIP=debug
# - CORE_CHAINCODE_STARTUPTIMEOUT=30s
- CORE_CHAINCODE_LOGGING_SHIM=debug
- CORE_CHAINCODE_LOGGING_LEVEL=debug
Expand All @@ -101,10 +103,13 @@ services:
- CORE_VM_DOCKER_ATTACHSTDOUT=true
- CORE_PEER_LOCALMSPID=Org1MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_LISTENADDRESS=0.0.0.0:7051
- CORE_PEER_ADDRESS=0.0.0.0:7051
- CORE_PEER_CHAINCODELISTENADDRESS=peer0.org1.example.com:7052
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_PEER_GOSSIP_BOOTSTRAP=127.0.0.1:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
- CORE_PEER_EVENTS_ADDRESS=0.0.0.0:7053
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/tls/peer/server.key
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/tls/peer/server.crt
Expand Down Expand Up @@ -148,6 +153,8 @@ services:
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- CORE_PEER_ID=peer0.org2.example.com
- CORE_LOGGING_PEER=debug
# - CORE_LOGGING_GRPC=debug
# - CORE_LOGGING_GOSSIP=debug
# - CORE_CHAINCODE_STARTUPTIMEOUT=30s
- CORE_CHAINCODE_LOGGING_SHIM=debug
- CORE_CHAINCODE_LOGGING_LEVEL=debug
Expand All @@ -157,10 +164,13 @@ services:
- CORE_VM_DOCKER_ATTACHSTDOUT=true
- CORE_PEER_LOCALMSPID=Org2MSP
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/peer/
- CORE_PEER_ADDRESS=0.0.0.0:7051
- CORE_PEER_LISTENADDRESS=0.0.0.0:8051
- CORE_PEER_ADDRESS=0.0.0.0:8051
- CORE_PEER_CHAINCODELISTENADDRESS=peer0.org2.example.com:7052
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
- CORE_PEER_GOSSIP_BOOTSTRAP=127.0.0.1:8051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:8051
- CORE_PEER_EVENTS_ADDRESS=0.0.0.0:8053
- CORE_PEER_TLS_ENABLED=true
- CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/tls/peer/server.key
- CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/tls/peer/server.crt
Expand All @@ -178,12 +188,12 @@ services:
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: peer node start
ports:
- "8051:7051"
- "8053:7053"
- "8051:8051"
- "8053:8053"
expose:
- "7051"
- "8051"
- "7052"
- "7053"
- "8053"
volumes:
- /var/run/:/host/var/run/
- ../fabric/${FABRIC_CRYPTOCONFIG_VERSION}/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/msp/peer
Expand Down
Binary file modified test/fixtures/fabric/v1.0.0/channel/mychannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/mychannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/orgchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/orgchannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/orgchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/testchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/testchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0.0/channel/twoorgs.genesis.block
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fixtures/fabric/v1.0.0/config/configtx.yaml
Expand Up @@ -87,7 +87,7 @@ Organizations:
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org2.example.com
Port: 7051
Port: 8051

################################################################################
#
Expand Down
Binary file modified test/fixtures/fabric/v1.0/channel/mychannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/mychannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/orgchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/orgchannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/orgchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/testchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/testchannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/testchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.0/channel/twoorgs.genesis.block
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fixtures/fabric/v1.0/config/configtx.yaml
Expand Up @@ -87,7 +87,7 @@ Organizations:
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org2.example.com
Port: 7051
Port: 8051

################################################################################
#
Expand Down
Binary file modified test/fixtures/fabric/v1.1.0-preview/channel/mychannel.tx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1.0-preview/channel/orgchannel.tx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1.0-preview/channel/testchannel.tx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fixtures/fabric/v1.1.0-preview/config/configtx.yaml
Expand Up @@ -87,7 +87,7 @@ Organizations:
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org2.example.com
Port: 7051
Port: 8051

################################################################################
#
Expand Down
Binary file modified test/fixtures/fabric/v1.1/channel/mychannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/mychannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/mychannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/orgchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/orgchannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/orgchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/testchannel.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/testchannelOrg1MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/testchannelOrg2MSPanchors.tx
Binary file not shown.
Binary file modified test/fixtures/fabric/v1.1/channel/twoorgs.genesis.block
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fixtures/fabric/v1.1/config/configtx.yaml
Expand Up @@ -87,7 +87,7 @@ Organizations:
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org2.example.com
Port: 7051
Port: 8051

################################################################################
#
Expand Down
1 change: 1 addition & 0 deletions test/scripts/integration.sh
Expand Up @@ -16,6 +16,7 @@ set -e
GO_CMD="${GO_CMD:-go}"
FABRIC_SDKGO_CODELEVEL_TAG="${FABRIC_SDKGO_CODELEVEL_TAG:-stable}"
FABRIC_CRYPTOCONFIG_VERSION="${FABRIC_CRYPTOCONFIG_VERSION:-v1}"
# TODO: better default handling for FABRIC_CRYPTOCONFIG_VERSION

# Packages to include in test run
PKGS=`$GO_CMD list github.com/hyperledger/fabric-sdk-go/test/integration/... 2> /dev/null | \
Expand Down

0 comments on commit 9a9856d

Please sign in to comment.