Skip to content

Commit

Permalink
[FAB-8703] Enable scc plugin tests on darwin
Browse files Browse the repository at this point in the history
Change-Id: I48ec6f403eee9df269ed85a7da79efdc4a6cdca9
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm committed Mar 8, 2018
1 parent 647f803 commit 7af4f2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
27 changes: 15 additions & 12 deletions core/scc/loadsysccs_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build pluginsenabled,go1.9,linux,cgo
// +build !ppc64le
// +build pluginsenabled,cgo
// +build darwin,go1.10 linux,go1.10 linux,go1.9,!ppc64le

/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
Expand All @@ -12,25 +12,30 @@ package scc
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
examplePluginPackage = "github.com/hyperledger/fabric/examples/plugins/scc"
pluginName = "testscc"
)

var pluginPath = os.TempDir() + "/scc-plugin.so"

func TestLoadSCCPlugin(t *testing.T) {
buildExamplePlugin(pluginPath, examplePluginPackage)
defer os.Remove(pluginPath)
tmpdir, err := ioutil.TempDir("", "scc-plugin")
require.NoError(t, err)

pluginPath := filepath.Join(tmpdir, "scc-plugin.so")
buildExamplePlugin(t, pluginPath, examplePluginPackage)
defer os.RemoveAll(tmpdir)

testConfig := fmt.Sprintf(`
chaincode:
Expand All @@ -51,15 +56,13 @@ func TestLoadSCCPlugin(t *testing.T) {
}

func TestLoadSCCPluginInvalid(t *testing.T) {
assert.Panics(t, func() { loadPlugin("/invalid/path.so") },
"expected panic with invalid path")
assert.Panics(t, func() { loadPlugin("missing.so") }, "expected panic with invalid path")
}

func buildExamplePlugin(path, pluginPackage string) {
cmd := exec.Command("go", "build", "-tags", goBuildTags, "-o", path, "-buildmode=plugin",
pluginPackage)
func buildExamplePlugin(t *testing.T, path, pluginPackage string) {
cmd := exec.Command("go", "build", "-tags", goBuildTags, "-o", path, "-buildmode=plugin", pluginPackage)
output, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Errorf("Error: %s, Could not build plugin: %s", err, string(output)))
t.Fatalf("Error: %s, Could not build plugin: %s", err, output)
}
}
2 changes: 1 addition & 1 deletion core/scc/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !pluginsenabled !linux ppc64le
// +build !pluginsenabled !cgo darwin,!go1.10 linux,!go1.9 linux,ppc64le,!go1.10

/*
Copyright IBM Corp. All Rights Reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build pluginsenabled,go1.9,linux,cgo
// +build !ppc64le
// +build pluginsenabled,cgo
// +build darwin,go1.10 linux,go1.10 linux,go1.9,!ppc64le

/*
Copyright IBM Corp. All Rights Reserved.
Expand Down

0 comments on commit 7af4f2e

Please sign in to comment.