Skip to content

Commit

Permalink
[FAB-1564] Create policies mock infrastructure
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1564

This is the first in a series of three patch sets to add broadcast
filtering by signature, this one introduces the mock testing
infrastructure that will be necessary to test the signature filter.

Change-Id: Ifb5e37b43117c21ae6df47241d618b61c1c33b7e
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jan 9, 2017
1 parent 01de0e4 commit 55aec5e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
43 changes: 43 additions & 0 deletions orderer/mocks/policies/policies.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package policies

import (
"github.com/hyperledger/fabric/common/policies"
cb "github.com/hyperledger/fabric/protos/common"
)

// Policy is a mock implementation of the policies.Policy interface
type Policy struct {
Err error
}

// Evaluate returns the Err set in Policy
func (p *Policy) Evaluate(signatureSet []*cb.SignedData) error {
return p.Err
}

// Manager is a mock implementation of the policies.Manager interface
type Manager struct {
// Policy is returned as the output to GetPolicy
Policy *Policy
}

// GetPolicy returns the value of Manager.Policy and whether it was nil or not
func (m *Manager) GetPolicy(id string) (policies.Policy, bool) {
return m.Policy, m.Policy != nil
}
31 changes: 31 additions & 0 deletions orderer/mocks/policies/policies_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package policies

import (
"testing"

"github.com/hyperledger/fabric/common/policies"
)

func TestPolicyManagerInterface(t *testing.T) {
_ = policies.Manager(&Manager{})
}

func TestPolicyInterface(t *testing.T) {
_ = policies.Policy(&Policy{})
}

0 comments on commit 55aec5e

Please sign in to comment.