Skip to content

Commit

Permalink
[FABG-851] Allow tests to run outside of GOPATH
Browse files Browse the repository at this point in the history
This change removes GOPATH from test paths & scripts.

Change-Id: I54ea0de2c54d823d28129485b0ace919ab301ad6
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Apr 11, 2019
1 parent 33f4504 commit 3e09cdf
Show file tree
Hide file tree
Showing 106 changed files with 924 additions and 688 deletions.
26 changes: 13 additions & 13 deletions Makefile
Expand Up @@ -110,7 +110,7 @@ FABRIC_CODELEVEL_UNITTEST_TAG ?= $(FABRIC_STABLE_CODELEVEL_TAG)
FABRIC_CODELEVEL_UNITTEST_VER ?= $(FABRIC_STABLE_CODELEVEL_VER)

# Local variables used by makefile
PACKAGE_NAME := github.com/hyperledger/fabric-sdk-go
PROJECT_NAME := fabric-sdk-go
ARCH := $(shell uname -m)
OS_NAME := $(shell uname -s)
FIXTURE_PROJECT_NAME := fabsdkgo
Expand Down Expand Up @@ -519,17 +519,17 @@ mock-gen:
crypto-gen:
@echo "Generating crypto directory ..."
@$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_CRYPTOCONFIG_VER) /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_crypto.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_CRYPTOCONFIG_VER) /opt/workspace/${PROJECT_NAME}/test/scripts/generate_crypto.sh"

.PHONY: channel-config-gen
channel-config-gen:
@echo "Generating test channel configuration transactions and blocks ..."
@$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_CODELEVEL_VER)/ /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_channeltx.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_CODELEVEL_VER)/ /opt/workspace/${PROJECT_NAME}/test/scripts/generate_channeltx.sh"

.PHONY: channel-config-all-gen
channel-config-all-gen: channel-config-stable-gen channel-config-prev-gen channel-config-prerelease-gen channel-config-devstable-gen
Expand All @@ -538,26 +538,26 @@ channel-config-all-gen: channel-config-stable-gen channel-config-prev-gen channe
channel-config-stable-gen:
@echo "Generating test channel configuration transactions and blocks (code level stable) ..."
@$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_STABLE_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_STABLE_CODELEVEL_VER)/ /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_channeltx.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_STABLE_CODELEVEL_VER)/ /opt/workspace/${PROJECT_NAME}/test/scripts/generate_channeltx.sh"

.PHONY: channel-config-prev-gen
channel-config-prev-gen:
@echo "Generating test channel configuration transactions and blocks (code level prev) ..."
$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_PREV_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_PREV_CODELEVEL_VER)/ /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_channeltx.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_PREV_CODELEVEL_VER)/ /opt/workspace/${PROJECT_NAME}/test/scripts/generate_channeltx.sh"

.PHONY: channel-config-prerelease-gen
channel-config-prerelease-gen:
ifneq ($(FABRIC_PRERELEASE_VERSION),)
@echo "Generating test channel configuration transactions and blocks (code level prerelease) ..."
$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_PRERELEASE_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_PRERELEASE_CODELEVEL_VER)/ /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_channeltx.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_PRERELEASE_CODELEVEL_VER)/ /opt/workspace/${PROJECT_NAME}/test/scripts/generate_channeltx.sh"
endif

.PHONY: channel-config-devstable-gen
Expand All @@ -566,9 +566,9 @@ ifeq ($(ARCH),x86_64)
@echo "Generating test channel configuration transactions and blocks (code level devstable) ..."
@$(FABRIC_DEV_REGISTRY_PRE_CMD) && \
$(DOCKER_CMD) run -i \
-v /$(abspath .):/opt/gopath/src/$(PACKAGE_NAME) -u $(shell id -u):$(shell id -g) \
-v /$(abspath .):/opt/workspace/$(PROJECT_NAME) -u $(shell id -u):$(shell id -g) \
$(FABRIC_DEV_REGISTRY)$(FABRIC_TOOLS_IMAGE):$(FABRIC_TOOLS_DEVSTABLE_TAG) \
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_DEVSTABLE_CODELEVEL_VER)/ /opt/gopath/src/${PACKAGE_NAME}/test/scripts/generate_channeltx.sh"
//bin/bash -c "FABRIC_VERSION_DIR=fabric/$(FABRIC_DEVSTABLE_CODELEVEL_VER)/ /opt/workspace/${PROJECT_NAME}/test/scripts/generate_channeltx.sh"
endif

.PHONY: thirdparty-pin
Expand Down
29 changes: 18 additions & 11 deletions README.md
Expand Up @@ -11,11 +11,7 @@ This SDK enables Go developers to build solutions that interact with [Hyperledge
Obtain the client SDK packages for Fabric and Fabric CA.

```bash
go get -u github.com/hyperledger/fabric-sdk-go

# Optional - populate vendor directory (if needed by your downstream vendoring solution)
# cd $GOPATH/src/github.com/hyperledger/fabric-sdk-go/
# make populate
go get github.com/hyperledger/fabric-sdk-go
```

You're good to go, happy coding! Check out the examples for usage demonstrations.
Expand Down Expand Up @@ -63,9 +59,20 @@ Once v1.3 is retired, the above client code logic will need to be removed as wel

### Running the test suite

Obtain the client SDK packages for Fabric and Fabric CA.

```bash
git clone https://github.com/hyperledger/fabric-sdk-go.git

# Alternatively, you should clone from gerrit to contribute. For example:
# git clone ssh://<username>@gerrit.hyperledger.org:29418/fabric-sdk-go && scp -p -P 29418 <username>@gerrit.hyperledger.org:hooks/commit-msg fabric-sdk-go/.git/hooks/
#
# See https://gerrit.hyperledger.org/
```

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

# Optional - Automatically install Go tools used by test suite
# make depend
Expand Down Expand Up @@ -108,7 +115,7 @@ To contribute patches, you will need to clone (or add a remote) from [Gerrit](ht

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

# Optional - Automatically install Go tools used by test suite
# make depend
Expand Down Expand Up @@ -144,7 +151,7 @@ The following commands starts Fabric:

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

# Start fabric (stable tag)
make dockerenv-stable-up
Expand All @@ -159,7 +166,7 @@ Fabric should now be running. In a different shell, run integration tests

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

# Use script to setup parameters for integration tests and execute them
# Previously we use to have hostnames like Fabric CA server, orderer and peer pointed to localhost
Expand All @@ -177,10 +184,10 @@ make integration-tests-local
# Now since we removed this now, We will be using a different config file config_test_local.yaml
# which has the Fabric CA server, orderer and peers pointed to localhost
# 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/
#cd fabric-sdk-go/test/integration/
#go test -args testLocal=true

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

# You should review test/scripts/integration.sh for options and details.
Expand Down
3 changes: 2 additions & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/client.go
Expand Up @@ -24,6 +24,8 @@ import (
"strconv"
"strings"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

cfsslapi "github.com/cloudflare/cfssl/api"
"github.com/cloudflare/cfssl/csr"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
Expand All @@ -34,7 +36,6 @@ import (
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/tls"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
)
Expand Down
Expand Up @@ -12,11 +12,10 @@ package x509

import (
"encoding/hex"
"net/http"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

"net/http"

factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge"

Expand Down
Expand Up @@ -14,9 +14,10 @@ import (
"crypto/x509"
"fmt"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/attrmgr"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/pkg/errors"
)

Expand Down
Expand Up @@ -21,9 +21,10 @@ Please review third_party pinning scripts and patches for more details.
package lib

import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

"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/lib/tls"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
)

// ClientConfig is the fabric-ca client's config
Expand Down
3 changes: 2 additions & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/tls/tls.go
Expand Up @@ -25,10 +25,11 @@ import (
"crypto/x509"
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/pkg/errors"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/github.com/hyperledger/fabric-ca/util/csp.go
Expand Up @@ -32,11 +32,12 @@ import (
"io/ioutil"
"strings"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"

"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/logbridge"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/pkg/errors"
)

Expand Down
6 changes: 5 additions & 1 deletion pkg/client/common/discovery/discoveryfilter_test.go
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package discovery

import (
"path/filepath"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/staticdiscovery"
Expand All @@ -15,8 +16,11 @@ import (
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
mocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
)

const configFile = "config_test.yaml"

type mockFilter struct {
called bool
}
Expand All @@ -29,7 +33,7 @@ func (df *mockFilter) Accept(peer fab.Peer) bool {

func TestDiscoveryFilter(t *testing.T) {

configBackend, err := config.FromFile("../../../../test/fixtures/config/config_test.yaml")()
configBackend, err := config.FromFile(filepath.Join(metadata.GetProjectPath(), metadata.SDKConfigPath, configFile))()
if err != nil {
t.Fatalf(err.Error())
}
Expand Down
Expand Up @@ -7,15 +7,19 @@ SPDX-License-Identifier: Apache-2.0
package staticdiscovery

import (
"path/filepath"
"testing"

"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/stretchr/testify/assert"
)

const configFile = "config_test.yaml"

func TestStaticDiscovery(t *testing.T) {

ctx := mocks.NewMockContext(mockmsp.NewMockSigningIdentity("user1", "Org1MSP"))
Expand Down Expand Up @@ -45,7 +49,8 @@ func TestStaticDiscoveryWhenChannelIsEmpty(t *testing.T) {
}

func TestStaticLocalDiscovery(t *testing.T) {
configBackend, err := config.FromFile("../../../../../test/fixtures/config/config_test.yaml")()
configPath := filepath.Join(metadata.GetProjectPath(), metadata.SDKConfigPath, configFile)
configBackend, err := config.FromFile(configPath)()
assert.NoError(t, err)

config1, err := fabImpl.ConfigFromBackend(configBackend...)
Expand Down
6 changes: 5 additions & 1 deletion pkg/client/msp/client_test.go
Expand Up @@ -12,6 +12,7 @@ import (
"math/rand"
"net"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
Expand All @@ -27,13 +28,14 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
mspImpl "github.com/hyperledger/fabric-sdk-go/pkg/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
caServerURLListen = "http://localhost:0"
configPath = "../../core/config/testdata/config_test.yaml"
configFile = "config_test.yaml"
)

var caServerURL string
Expand Down Expand Up @@ -211,6 +213,7 @@ func TestMSPWithAttributeRequests(t *testing.T) {

func TestWithNonExistentOrganization(t *testing.T) {
// Instantiate the SDK
configPath := filepath.Join(metadata.GetProjectPath(), metadata.SDKConfigPath, configFile)
sdk, err := fabsdk.New(config.FromFile(configPath))
if err != nil {
t.Fatalf("SDK init failed: %s", err)
Expand Down Expand Up @@ -466,6 +469,7 @@ func (f *testFixture) setup() *fabsdk.FabricSDK {
caServerURL = "http://" + lis.Addr().String()
}

configPath := filepath.Join(metadata.GetProjectPath(), metadata.SDKConfigPath, configFile)
backend, err := config.FromFile(configPath)()
if err != nil {
panic(err)
Expand Down
11 changes: 8 additions & 3 deletions pkg/client/resmgmt/example_test.go
Expand Up @@ -8,6 +8,7 @@ package resmgmt
import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/cauthdsl"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/resource"
mspmocks "github.com/hyperledger/fabric-sdk-go/pkg/msp/test/mockmsp"
"github.com/hyperledger/fabric-sdk-go/test/metadata"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
)

Expand All @@ -29,7 +31,8 @@ func Example() {
}

// Read channel configuration
r, err := os.Open(channelConfig)
channelConfigPath := filepath.Join(metadata.GetProjectPath(), metadata.ChannelConfigPath, channelConfigFile)
r, err := os.Open(channelConfigPath)
if err != nil {
fmt.Printf("failed to open channel config: %s\n", err)
}
Expand Down Expand Up @@ -191,7 +194,8 @@ func ExampleClient_SaveChannel() {
fmt.Printf("failed to create client: %s\n", err)
}

r, err := os.Open(channelConfig)
channelConfigPath := filepath.Join(metadata.GetProjectPath(), metadata.ChannelConfigPath, channelConfigFile)
r, err := os.Open(channelConfigPath)
if err != nil {
fmt.Printf("failed to open channel config: %s\n", err)
}
Expand All @@ -218,7 +222,8 @@ func ExampleClient_SaveChannel_withOrdererEndpoint() {
fmt.Printf("failed to create client: %s\n", err)
}

r, err := os.Open(channelConfig)
channelConfigPath := filepath.Join(metadata.GetProjectPath(), metadata.ChannelConfigPath, channelConfigFile)
r, err := os.Open(channelConfigPath)
if err != nil {
fmt.Printf("failed to open channel config: %s\n", err)
}
Expand Down

0 comments on commit 3e09cdf

Please sign in to comment.