-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Jan 9, 2017
1 parent
01de0e4
commit 55aec5e
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |