Skip to content

Commit 82b9612

Browse files
author
Jason Yellick
committed
[FAB-5715] Rm policies.Manager unused interfaces
There are some methods in the policies.Manager interface which are not used outside of the policies package. This makes other implementations and mocks of this interface more difficult to do, and generally goes against the go best practice of defining small interfaces. Change-Id: Icb44640d950704f43ea8e5670dd403c3b81b3075 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 7c8342a commit 82b9612

File tree

6 files changed

+10
-47
lines changed

6 files changed

+10
-47
lines changed

common/configtx/update_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,10 @@ func TestPolicyForItem(t *testing.T) {
142142
cm := &configManager{
143143
initializer: &mockconfigtx.Initializer{
144144
PolicyManagerVal: &mockpolicies.Manager{
145-
BasePathVal: "root",
146-
Policy: rootPolicy,
145+
Policy: rootPolicy,
147146
SubManagersMap: map[string]*mockpolicies.Manager{
148147
"foo": &mockpolicies.Manager{
149-
Policy: fooPolicy,
150-
BasePathVal: "foo",
148+
Policy: fooPolicy,
151149
},
152150
},
153151
},

common/mocks/policies/policies.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,13 @@ type Manager struct {
3838
// for id is not in PolicyMap
3939
Policy *Policy
4040

41-
// BasePathVal is returned as the result of BasePath
42-
BasePathVal string
43-
4441
// PolicyMap is returned is used to look up Policies in
4542
PolicyMap map[string]policies.Policy
4643

4744
// SubManagers is used for the return value of Manager
4845
SubManagersMap map[string]*Manager
4946
}
5047

51-
// PolicyNames panics
52-
func (m *Manager) PolicyNames() []string {
53-
panic("Unimplemented")
54-
}
55-
56-
// BasePath returns BasePathVal
57-
func (m *Manager) BasePath() string {
58-
return m.BasePathVal
59-
}
60-
6148
// Manager returns the Manager from SubManagers for the last component of the path
6249
func (m *Manager) Manager(path []string) (policies.Manager, bool) {
6350
if len(path) == 0 {

common/policies/policy.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ type Manager interface {
7575

7676
// Manager returns the sub-policy manager for a given path and whether it exists
7777
Manager(path []string) (Manager, bool)
78-
79-
// Basepath returns the basePath the manager was instantiated with
80-
BasePath() string
81-
82-
// Policies returns all policy names defined in the manager
83-
PolicyNames() []string
8478
}
8579

8680
// Proposer is the interface used by the configtx manager for policy management

common/policies/policy_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ func TestNestedManager(t *testing.T) {
148148
_, ok := n1.GetPolicy(policyName)
149149
assert.True(t, ok, "Should have found policy %s", policyName)
150150

151-
_, ok = m.GetPolicy(n1.BasePath() + "/" + policyName)
151+
_, ok = m.GetPolicy(n1.(*ManagerImpl).BasePath() + "/" + policyName)
152152
assert.True(t, ok, "Should have found policy %s", policyName)
153153

154154
for i, abs := range []Manager{n1, m} {
155-
absName := absPrefix + n1.BasePath() + "/" + policyName
155+
absName := absPrefix + n1.(*ManagerImpl).BasePath() + "/" + policyName
156156
_, ok = abs.GetPolicy(absName)
157157
assert.True(t, ok, "Should have found absolutely policy for manager %d", i)
158158
}
@@ -162,14 +162,14 @@ func TestNestedManager(t *testing.T) {
162162
_, ok := n2a.GetPolicy(policyName)
163163
assert.True(t, ok, "Should have found policy %s", policyName)
164164

165-
_, ok = n1.GetPolicy(n2a.BasePath() + "/" + policyName)
165+
_, ok = n1.GetPolicy(n2a.(*ManagerImpl).BasePath() + "/" + policyName)
166166
assert.True(t, ok, "Should have found policy %s", policyName)
167167

168-
_, ok = m.GetPolicy(n1.BasePath() + "/" + n2a.BasePath() + "/" + policyName)
168+
_, ok = m.GetPolicy(n1.(*ManagerImpl).BasePath() + "/" + n2a.(*ManagerImpl).BasePath() + "/" + policyName)
169169
assert.True(t, ok, "Should have found policy %s", policyName)
170170

171171
for i, abs := range []Manager{n2a, n1, m} {
172-
absName := absPrefix + n1.BasePath() + "/" + n2a.BasePath() + "/" + policyName
172+
absName := absPrefix + n1.(*ManagerImpl).BasePath() + "/" + n2a.(*ManagerImpl).BasePath() + "/" + policyName
173173
_, ok = abs.GetPolicy(absName)
174174
assert.True(t, ok, "Should have found absolutely policy for manager %d", i)
175175
}
@@ -179,14 +179,14 @@ func TestNestedManager(t *testing.T) {
179179
_, ok := n2b.GetPolicy(policyName)
180180
assert.True(t, ok, "Should have found policy %s", policyName)
181181

182-
_, ok = n1.GetPolicy(n2b.BasePath() + "/" + policyName)
182+
_, ok = n1.GetPolicy(n2b.(*ManagerImpl).BasePath() + "/" + policyName)
183183
assert.True(t, ok, "Should have found policy %s", policyName)
184184

185-
_, ok = m.GetPolicy(n1.BasePath() + "/" + n2b.BasePath() + "/" + policyName)
185+
_, ok = m.GetPolicy(n1.(*ManagerImpl).BasePath() + "/" + n2b.(*ManagerImpl).BasePath() + "/" + policyName)
186186
assert.True(t, ok, "Should have found policy %s", policyName)
187187

188188
for i, abs := range []Manager{n2b, n1, m} {
189-
absName := absPrefix + n1.BasePath() + "/" + n2b.BasePath() + "/" + policyName
189+
absName := absPrefix + n1.(*ManagerImpl).BasePath() + "/" + n2b.(*ManagerImpl).BasePath() + "/" + policyName
190190
_, ok = abs.GetPolicy(absName)
191191
assert.True(t, ok, "Should have found absolutely policy for manager %d", i)
192192
}

core/policy/mocks/mocks.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ func (m *MockChannelPolicyManager) Manager(path []string) (policies.Manager, boo
4949
panic("Not implemented")
5050
}
5151

52-
func (m *MockChannelPolicyManager) BasePath() string {
53-
panic("Not implemented")
54-
}
55-
56-
func (m *MockChannelPolicyManager) PolicyNames() []string {
57-
panic("Not implemented")
58-
}
59-
6052
type MockPolicy struct {
6153
Deserializer msp.IdentityDeserializer
6254
}

peer/gossip/mocks/mocks.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ func (m *ChannelPolicyManager) Manager(path []string) (policies.Manager, bool) {
5656
panic("Not implemented")
5757
}
5858

59-
func (m *ChannelPolicyManager) BasePath() string {
60-
panic("Not implemented")
61-
}
62-
63-
func (m *ChannelPolicyManager) PolicyNames() []string {
64-
panic("Not implemented")
65-
}
66-
6759
type Policy struct {
6860
Deserializer msp.IdentityDeserializer
6961
}

0 commit comments

Comments
 (0)