Skip to content

Commit

Permalink
admission_test.go(setupClientSet): extract function.
Browse files Browse the repository at this point in the history
  • Loading branch information
php-coder committed Nov 14, 2017
1 parent f51843c commit 072358b
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pkg/security/admission/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ func TestAdmitCaps(t *testing.T) {
}

func testSCCAdmit(testCaseName string, sccs []*securityapi.SecurityContextConstraints, pod *kapi.Pod, shouldPass bool, t *testing.T) {
namespace := admissiontesting.CreateNamespaceForTest()
serviceAccount := admissiontesting.CreateSAForTest()
tc := clientsetfake.NewSimpleClientset(namespace, serviceAccount)
tc := setupClientSet()
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
cache := securitylisters.NewSecurityContextConstraintsLister(indexer)
for _, scc := range sccs {
Expand All @@ -180,15 +178,11 @@ func testSCCAdmit(testCaseName string, sccs []*securityapi.SecurityContextConstr
}

func TestAdmitSuccess(t *testing.T) {
// create the annotated namespace and add it to the fake client
namespace := admissiontesting.CreateNamespaceForTest()
serviceAccount := admissiontesting.CreateSAForTest()
tc := setupClientSet()

// used for cases where things are preallocated
defaultGroup := int64(2)

tc := clientsetfake.NewSimpleClientset(namespace, serviceAccount)

// create scc that requires allocation retrieval
saSCC := &securityapi.SecurityContextConstraints{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -374,11 +368,7 @@ func TestAdmitSuccess(t *testing.T) {
}

func TestAdmitFailure(t *testing.T) {
// create the annotated namespace and add it to the fake client
namespace := admissiontesting.CreateNamespaceForTest()
serviceAccount := admissiontesting.CreateSAForTest()

tc := clientsetfake.NewSimpleClientset(namespace, serviceAccount)
tc := setupClientSet()

// create scc that requires allocation retrieval
saSCC := &securityapi.SecurityContextConstraints{
Expand Down Expand Up @@ -954,10 +944,7 @@ func TestAdmitWithPrioritizedSCC(t *testing.T) {
// SCCs and ensure that they come out with the right annotation. This means admission
// is using the sort strategy we expect.

namespace := admissiontesting.CreateNamespaceForTest()
serviceAccount := admissiontesting.CreateSAForTest()
serviceAccount.Namespace = namespace.Name
tc := clientsetfake.NewSimpleClientset(namespace, serviceAccount)
tc := setupClientSet()

indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
cache := securitylisters.NewSecurityContextConstraintsLister(indexer)
Expand Down Expand Up @@ -1191,3 +1178,12 @@ func goodPod() *kapi.Pod {
},
}
}

func setupClientSet() *clientsetfake.Clientset {
// create the annotated namespace and add it to the fake client
namespace := admissiontesting.CreateNamespaceForTest()
serviceAccount := admissiontesting.CreateSAForTest()
serviceAccount.Namespace = namespace.Name

return clientsetfake.NewSimpleClientset(namespace, serviceAccount)
}

0 comments on commit 072358b

Please sign in to comment.