From 55aec5e46c626b0240cd9c454ac01e1e8df9c578 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Mon, 9 Jan 2017 13:23:50 -0500 Subject: [PATCH] [FAB-1564] Create policies mock infrastructure 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 --- orderer/mocks/policies/policies.go | 43 +++++++++++++++++++++++++ orderer/mocks/policies/policies_test.go | 31 ++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 orderer/mocks/policies/policies.go create mode 100644 orderer/mocks/policies/policies_test.go diff --git a/orderer/mocks/policies/policies.go b/orderer/mocks/policies/policies.go new file mode 100644 index 00000000000..97994d64782 --- /dev/null +++ b/orderer/mocks/policies/policies.go @@ -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 +} diff --git a/orderer/mocks/policies/policies_test.go b/orderer/mocks/policies/policies_test.go new file mode 100644 index 00000000000..c01af1414e1 --- /dev/null +++ b/orderer/mocks/policies/policies_test.go @@ -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{}) +}