Skip to content

Commit

Permalink
Skip plugin tests when the noplugin tag is used (#2535)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Sykes <[email protected]>
  • Loading branch information
sykesm authored Apr 9, 2021
1 parent ba7e923 commit 4cfc722
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
12 changes: 12 additions & 0 deletions core/handlers/library/noplugin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build noplugin

/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package library

func init() {
noplugin = true
}
32 changes: 28 additions & 4 deletions core/handlers/library/registry_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ const (
validationTestPlugin = "github.com/hyperledger/fabric/core/handlers/validation/testdata/"
)

// raceEnabled is set to true when the race build tag is enabled.
// see race_test.go
var raceEnabled bool
var (
// raceEnabled is set to true when the race build tag is enabled.
// See race_test.go
raceEnabled bool
// noplugin is set to true when the noplugin tag is enabled.
// See noplugin_test.go
noplugin bool
)

func buildPlugin(t *testing.T, dest, pkg string) {
cmd := exec.Command("go", "build", "-o", dest, "-buildmode=plugin")
Expand All @@ -43,7 +48,9 @@ func buildPlugin(t *testing.T, dest, pkg string) {
}

func TestLoadAuthPlugin(t *testing.T) {
endorser := &mockEndorserServer{}
if noplugin {
t.Skip("plugins disabled")
}

testDir, err := ioutil.TempDir("", "")
require.NoError(t, err, "Could not create temp directory for plugins")
Expand All @@ -56,12 +63,17 @@ func TestLoadAuthPlugin(t *testing.T) {
testReg.loadPlugin(pluginPath, Auth)
require.Len(t, testReg.filters, 1, "Expected filter to be registered")

endorser := &mockEndorserServer{}
testReg.filters[0].Init(endorser)
testReg.filters[0].ProcessProposal(context.TODO(), nil)
require.True(t, endorser.invoked, "Expected filter to invoke endorser on invoke")
}

func TestLoadDecoratorPlugin(t *testing.T) {
if noplugin {
t.Skip("plugins disabled")
}

testProposal := &peer.Proposal{Payload: []byte("test")}
testInput := &peer.ChaincodeInput{Args: [][]byte{[]byte("test")}}

Expand All @@ -81,6 +93,10 @@ func TestLoadDecoratorPlugin(t *testing.T) {
}

func TestEndorsementPlugin(t *testing.T) {
if noplugin {
t.Skip("plugins disabled")
}

testDir, err := ioutil.TempDir("", "")
require.NoError(t, err, "Could not create temp directory for plugins")
defer os.Remove(testDir)
Expand All @@ -102,6 +118,10 @@ func TestEndorsementPlugin(t *testing.T) {
}

func TestValidationPlugin(t *testing.T) {
if noplugin {
t.Skip("plugins disabled")
}

testDir, err := ioutil.TempDir("", "")
require.NoError(t, err, "Could not create temp directory for plugins")
defer os.Remove(testDir)
Expand All @@ -122,6 +142,10 @@ func TestValidationPlugin(t *testing.T) {
}

func TestLoadPluginInvalidPath(t *testing.T) {
if noplugin {
t.Skip("plugins disabled")
}

defer func() {
if r := recover(); r == nil {
t.Errorf("Expected panic with incorrect plugin path")
Expand Down

0 comments on commit 4cfc722

Please sign in to comment.