Skip to content

Commit 7af4f2e

Browse files
committed
[FAB-8703] Enable scc plugin tests on darwin
Change-Id: I48ec6f403eee9df269ed85a7da79efdc4a6cdca9 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 647f803 commit 7af4f2e

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

core/scc/loadsysccs_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// +build pluginsenabled,go1.9,linux,cgo
2-
// +build !ppc64le
1+
// +build pluginsenabled,cgo
2+
// +build darwin,go1.10 linux,go1.10 linux,go1.9,!ppc64le
33

44
/*
55
Copyright SecureKey Technologies Inc. All Rights Reserved.
@@ -12,25 +12,30 @@ package scc
1212
import (
1313
"bytes"
1414
"fmt"
15+
"io/ioutil"
1516
"os"
1617
"os/exec"
18+
"path/filepath"
1719
"testing"
1820

1921
"github.com/hyperledger/fabric/core/chaincode/shim"
2022
"github.com/spf13/viper"
2123
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2225
)
2326

2427
const (
2528
examplePluginPackage = "github.com/hyperledger/fabric/examples/plugins/scc"
2629
pluginName = "testscc"
2730
)
2831

29-
var pluginPath = os.TempDir() + "/scc-plugin.so"
30-
3132
func TestLoadSCCPlugin(t *testing.T) {
32-
buildExamplePlugin(pluginPath, examplePluginPackage)
33-
defer os.Remove(pluginPath)
33+
tmpdir, err := ioutil.TempDir("", "scc-plugin")
34+
require.NoError(t, err)
35+
36+
pluginPath := filepath.Join(tmpdir, "scc-plugin.so")
37+
buildExamplePlugin(t, pluginPath, examplePluginPackage)
38+
defer os.RemoveAll(tmpdir)
3439

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

5358
func TestLoadSCCPluginInvalid(t *testing.T) {
54-
assert.Panics(t, func() { loadPlugin("/invalid/path.so") },
55-
"expected panic with invalid path")
59+
assert.Panics(t, func() { loadPlugin("missing.so") }, "expected panic with invalid path")
5660
}
5761

58-
func buildExamplePlugin(path, pluginPackage string) {
59-
cmd := exec.Command("go", "build", "-tags", goBuildTags, "-o", path, "-buildmode=plugin",
60-
pluginPackage)
62+
func buildExamplePlugin(t *testing.T, path, pluginPackage string) {
63+
cmd := exec.Command("go", "build", "-tags", goBuildTags, "-o", path, "-buildmode=plugin", pluginPackage)
6164
output, err := cmd.CombinedOutput()
6265
if err != nil {
63-
panic(fmt.Errorf("Error: %s, Could not build plugin: %s", err, string(output)))
66+
t.Fatalf("Error: %s, Could not build plugin: %s", err, output)
6467
}
6568
}

core/scc/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !pluginsenabled !linux ppc64le
1+
// +build !pluginsenabled !cgo darwin,!go1.10 linux,!go1.9 linux,ppc64le,!go1.10
22

33
/*
44
Copyright IBM Corp. All Rights Reserved.

core/scc/register_plugins.go renamed to core/scc/register_pluginsenabled.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// +build pluginsenabled,go1.9,linux,cgo
2-
// +build !ppc64le
1+
// +build pluginsenabled,cgo
2+
// +build darwin,go1.10 linux,go1.10 linux,go1.9,!ppc64le
33

44
/*
55
Copyright IBM Corp. All Rights Reserved.

0 commit comments

Comments
 (0)