Skip to content

Commit

Permalink
[FAB-7412] Return error when cc src dir is empty
Browse files Browse the repository at this point in the history
The peer CLI should return an error if there
are no source files in src path when running
the install and/or package commands.

This fixes the issue for the Java and Node
platforms and adds a test for the Golang
platform (which already handled the error).

Change-Id: Iaf732308f9f377e0e701ecac03980adeb8fea611
Signed-off-by: Gari Singh <[email protected]>
  • Loading branch information
mastersingh24 committed Dec 17, 2017
1 parent 341159b commit 20f5006
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 347 deletions.
314 changes: 0 additions & 314 deletions core/chaincode/platforms/golang/platform_go19_test.go

This file was deleted.

34 changes: 25 additions & 9 deletions core/chaincode/platforms/golang/platform_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !go1.9
// +build go1.9

/*
Copyright IBM Corp. All Rights Reserved.
Expand All @@ -14,6 +14,7 @@ import (
"compress/gzip"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -100,18 +101,15 @@ func TestValidateCDS(t *testing.T) {
}

func TestPlatform_GoPathNotSet(t *testing.T) {
p := &Platform{}
spec := &pb.ChaincodeSpec{
ChaincodeId: &pb.ChaincodeID{
Path: "/opt/gopath/src/github.com/hyperledger/fabric",
},
}
gopath := os.Getenv("GOPATH")
defer os.Setenv("GOPATH", gopath)
os.Setenv("GOPATH", "")

err := p.ValidateSpec(spec)
assert.Contains(t, err.Error(), "invalid GOPATH environment variable value")
// Go 1.9 sets GOPATH to $HOME/go if GOPATH is not set
defaultGopath := filepath.Join(os.Getenv("HOME"), "go")
currentGopath, err := getGopath()
assert.NoError(t, err, "Expected default GOPATH")
assert.Equal(t, defaultGopath, currentGopath)
}

func Test_findSource(t *testing.T) {
Expand Down Expand Up @@ -225,6 +223,10 @@ func TestValidateSpec(t *testing.T) {
}

func TestGetDeploymentPayload(t *testing.T) {
emptyDir := fmt.Sprintf("pkg%d", os.Getpid())
os.Mkdir(emptyDir, os.ModePerm)
defer os.Remove(emptyDir)

platform := &Platform{}

var tests = []struct {
Expand All @@ -234,16 +236,30 @@ func TestGetDeploymentPayload(t *testing.T) {
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/examples/chaincode/go/map"}}, succ: true},
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/examples/bad/go/map"}}, succ: false},
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/test/chaincodes/BadImport"}}, succ: false},
{spec: &pb.ChaincodeSpec{ChaincodeId: &pb.ChaincodeID{Name: "Test Chaincode", Path: "github.com/hyperledger/fabric/core/chaincode/platforms/golang/" + emptyDir}}, succ: false},
}

for _, tst := range tests {
_, err := platform.GetDeploymentPayload(tst.spec)
t.Log(err)
if err = testerr(err, tst.succ); err != nil {
t.Errorf("Error validating chaincode spec: %s, %s", tst.spec.ChaincodeId.Path, err)
}
}
}

//TestGetLDFlagsOpts tests handling of chaincode.golang.dynamicLink
func TestGetLDFlagsOpts(t *testing.T) {
viper.Set("chaincode.golang.dynamicLink", true)
if getLDFlagsOpts() != dynamicLDFlagsOpts {
t.Error("Error handling chaincode.golang.dynamicLink configuration. ldflags should be for dynamic linkink")
}
viper.Set("chaincode.golang.dynamicLink", false)
if getLDFlagsOpts() != staticLDFlagsOpts {
t.Error("Error handling chaincode.golang.dynamicLink configuration. ldflags should be for static linkink")
}
}

//TestGenerateDockerBuild goes through the functions needed to do docker build
func TestGenerateDockerBuild(t *testing.T) {
platform := &Platform{}
Expand Down
Loading

0 comments on commit 20f5006

Please sign in to comment.