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
3
3
4
4
/*
5
5
Copyright SecureKey Technologies Inc. All Rights Reserved.
@@ -12,25 +12,30 @@ package scc
12
12
import (
13
13
"bytes"
14
14
"fmt"
15
+ "io/ioutil"
15
16
"os"
16
17
"os/exec"
18
+ "path/filepath"
17
19
"testing"
18
20
19
21
"github.com/hyperledger/fabric/core/chaincode/shim"
20
22
"github.com/spf13/viper"
21
23
"github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
22
25
)
23
26
24
27
const (
25
28
examplePluginPackage = "github.com/hyperledger/fabric/examples/plugins/scc"
26
29
pluginName = "testscc"
27
30
)
28
31
29
- var pluginPath = os .TempDir () + "/scc-plugin.so"
30
-
31
32
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 )
34
39
35
40
testConfig := fmt .Sprintf (`
36
41
chaincode:
@@ -51,15 +56,13 @@ func TestLoadSCCPlugin(t *testing.T) {
51
56
}
52
57
53
58
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" )
56
60
}
57
61
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 )
61
64
output , err := cmd .CombinedOutput ()
62
65
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 )
64
67
}
65
68
}
0 commit comments