Skip to content

Commit ae97160

Browse files
committed
admission_test.go(createSCCListerAndIndexer): introduce and use function.
1 parent 0cdb8b1 commit ae97160

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/security/admission/admission_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,10 @@ func TestAdmitFailure(t *testing.T) {
417417
Groups: []string{"system:serviceaccounts"},
418418
}
419419

420-
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
421-
lister := securitylisters.NewSecurityContextConstraintsLister(indexer)
422-
423-
indexer.Add(saExactSCC)
424-
indexer.Add(saSCC)
420+
lister, indexer := createSCCListerAndIndexer(t, []*securityapi.SecurityContextConstraints{
421+
saExactSCC,
422+
saSCC,
423+
})
425424

426425
// create the admission plugin
427426
p := NewTestAdmission(lister, tc)
@@ -1169,13 +1168,18 @@ func setupClientSet() *clientsetfake.Clientset {
11691168
return clientsetfake.NewSimpleClientset(namespace, serviceAccount)
11701169
}
11711170

1172-
func createSCCLister(t *testing.T, sccs []*securityapi.SecurityContextConstraints) securitylisters.SecurityContextConstraintsLister {
1171+
func createSCCListerAndIndexer(t *testing.T, sccs []*securityapi.SecurityContextConstraints) (securitylisters.SecurityContextConstraintsLister, cache.Indexer) {
11731172
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
11741173
lister := securitylisters.NewSecurityContextConstraintsLister(indexer)
11751174
for _, scc := range sccs {
11761175
if err := indexer.Add(scc); err != nil {
11771176
t.Fatalf("error adding SCC to store: %v", err)
11781177
}
11791178
}
1179+
return lister, indexer
1180+
}
1181+
1182+
func createSCCLister(t *testing.T, sccs []*securityapi.SecurityContextConstraints) securitylisters.SecurityContextConstraintsLister {
1183+
lister, _ := createSCCListerAndIndexer(t, sccs)
11801184
return lister
11811185
}

0 commit comments

Comments
 (0)