-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore delegated_test.go #16180
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
mrogers950:delegated_test
Jan 20, 2018
Merged
Restore delegated_test.go #16180
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
pkg/project/registry/projectrequest/delegated/delegated_test.go
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,89 @@ | ||
package delegated | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
rbaclisters "k8s.io/kubernetes/pkg/client/listers/rbac/internalversion" | ||
|
||
"github.com/go-openapi/errors" | ||
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" | ||
) | ||
|
||
func TestDelegatedWait(t *testing.T) { | ||
cache := &testRoleBindingLister{} | ||
storage := &REST{roleBindings: cache} | ||
|
||
cache.namespacelister = &testRoleBindingNamespaceLister{} | ||
cache.namespacelister.bindings = map[string]*rbac.RoleBinding{} | ||
cache.namespacelister.bindings["anything"] = nil | ||
|
||
waitReturnedCh := waitForResultChannel(storage) | ||
|
||
select { | ||
case <-waitReturnedCh: | ||
t.Error("waitForRoleBinding() failed to block pending rolebinding creation") | ||
case <-time.After(1 * time.Second): | ||
} | ||
|
||
cache.addAdminRolebinding() | ||
|
||
select { | ||
case <-waitReturnedCh: | ||
case <-time.After(1 * time.Second): | ||
t.Error("waitForRoleBinding() failed to unblock after rolebinding creation") | ||
} | ||
} | ||
|
||
func waitForResultChannel(storage *REST) chan struct{} { | ||
ret := make(chan struct{}) | ||
|
||
go func() { | ||
storage.waitForRoleBinding("foo", bootstrappolicy.AdminRoleName) | ||
close(ret) | ||
}() | ||
|
||
return ret | ||
} | ||
|
||
type testRoleBindingNamespaceLister struct { | ||
bindings map[string]*rbac.RoleBinding | ||
lock sync.Mutex | ||
} | ||
|
||
func (t *testRoleBindingNamespaceLister) List(selector labels.Selector) (ret []*rbac.RoleBinding, err error) { | ||
return ret, nil | ||
} | ||
|
||
func (t *testRoleBindingNamespaceLister) Get(name string) (*rbac.RoleBinding, error) { | ||
t.lock.Lock() | ||
defer t.lock.Unlock() | ||
if t.bindings[bootstrappolicy.AdminRoleName] != nil { | ||
return t.bindings[bootstrappolicy.AdminRoleName], nil | ||
} | ||
return nil, errors.NotFound("could not find role " + bootstrappolicy.AdminRoleName) | ||
} | ||
|
||
type testRoleBindingLister struct { | ||
namespacelister *testRoleBindingNamespaceLister | ||
} | ||
|
||
func (t *testRoleBindingLister) RoleBindings(namespace string) rbaclisters.RoleBindingNamespaceLister { | ||
return t.namespacelister | ||
} | ||
|
||
func (t *testRoleBindingLister) List(selector labels.Selector) ([]*rbac.RoleBinding, error) { | ||
return nil, nil | ||
} | ||
|
||
func (t *testRoleBindingLister) addAdminRolebinding() { | ||
t.namespacelister.lock.Lock() | ||
defer t.namespacelister.lock.Unlock() | ||
t.namespacelister.bindings[bootstrappolicy.AdminRoleName] = &rbac.RoleBinding{ | ||
ObjectMeta: metav1.ObjectMeta{Name: bootstrappolicy.AdminRoleName}, | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to split this to 2 functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P.S. Unless I miss something. Do we really need to check 2 cases sequentially within one test method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, to test the unblock we want to ensure it blocked in the first place, so it makes sense to me to have this sequence in one test.