Fix golint failures of e2e/framework/[a-c].go

This fixes golint failures on the following files:
- test/e2e/framework/authorizer_util.go
- test/e2e/framework/cleanup.go
- test/e2e/framework/create.go
k3s-v1.15.3
Kenichi Omichi 2019-03-22 21:16:45 +00:00
parent b3824cd094
commit 63f44a0bbf
3 changed files with 25 additions and 19 deletions

View File

@ -42,7 +42,7 @@ func WaitForAuthorizationUpdate(c v1beta1authorization.SubjectAccessReviewsGette
return WaitForNamedAuthorizationUpdate(c, user, namespace, verb, "", resource, allowed)
}
// WaitForAuthorizationUpdate checks if the given user can perform the named verb and action on the named resource.
// WaitForNamedAuthorizationUpdate checks if the given user can perform the named verb and action on the named resource.
// If policyCachePollTimeout is reached without the expected condition matching, an error is returned
func WaitForNamedAuthorizationUpdate(c v1beta1authorization.SubjectAccessReviewsGetter, user, namespace, verb, resourceName string, resource schema.GroupResource, allowed bool) error {
review := &authorizationv1beta1.SubjectAccessReview{
@ -133,6 +133,7 @@ var (
isRBACEnabled bool
)
// IsRBACEnabled returns true if RBAC is enabled. Otherwise false.
func IsRBACEnabled(f *Framework) bool {
isRBACEnabledOnce.Do(func() {
crs, err := f.ClientSet.RbacV1().ClusterRoles().List(metav1.ListOptions{})

View File

@ -18,6 +18,7 @@ package framework
import "sync"
// CleanupActionHandle is an integer pointer type for handling cleanup action
type CleanupActionHandle *int
var cleanupActionsLock sync.Mutex

View File

@ -38,7 +38,7 @@ import (
// LoadFromManifests loads .yaml or .json manifest files and returns
// all items that it finds in them. It supports all items for which
// there is a factory registered in Factories and .yaml files with
// there is a factory registered in factories and .yaml files with
// multiple items separated by "---". Files are accessed via the
// "testfiles" package, which means they can come from a file system
// or be built into the binary.
@ -58,7 +58,7 @@ func (f *Framework) LoadFromManifests(files ...string) ([]interface{}, error) {
return errors.Wrap(err, "decode TypeMeta")
}
factory := Factories[what]
factory := factories[what]
if factory == nil {
return errors.Errorf("item of type %+v not supported", what)
}
@ -167,7 +167,7 @@ func (f *Framework) CreateItems(items ...interface{}) (func(), error) {
// Uncomment this line to get a full dump of the entire item.
// description = fmt.Sprintf("%s:\n%s", description, PrettyPrint(item))
Logf("creating %s", description)
for _, factory := range Factories {
for _, factory := range factories {
destructor, err := factory.Create(f, item)
if destructor != nil {
destructors = append(destructors, func() error {
@ -178,7 +178,7 @@ func (f *Framework) CreateItems(items ...interface{}) (func(), error) {
if err == nil {
done = true
break
} else if errors.Cause(err) != ItemNotSupported {
} else if errors.Cause(err) != errorItemNotSupported {
result = err
break
}
@ -224,18 +224,22 @@ type What struct {
Kind string `json:"kind"`
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new What.
func (in *What) DeepCopy() *What {
return &What{Kind: in.Kind}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out.
func (in *What) DeepCopyInto(out *What) {
out.Kind = in.Kind
}
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
func (in *What) DeepCopyObject() runtime.Object {
return &What{Kind: in.Kind}
}
// GetObjectKind returns the ObjectKind schema
func (in *What) GetObjectKind() schema.ObjectKind {
return nil
}
@ -250,7 +254,7 @@ type ItemFactory interface {
// Create is responsible for creating the item. It returns an
// error or a cleanup function for the created item.
// If the item is of an unsupported type, it must return
// an error that has ItemNotSupported as cause.
// an error that has errorItemNotSupported as cause.
Create(f *Framework, item interface{}) (func() error, error)
}
@ -266,11 +270,11 @@ func DescribeItem(item interface{}) string {
return fmt.Sprintf("%T: %s", item, item)
}
// ItemNotSupported is the error that Create methods
// errorItemNotSupported is the error that Create methods
// must return or wrap when they don't support the given item.
var ItemNotSupported = errors.New("not supported")
var errorItemNotSupported = errors.New("not supported")
var Factories = map[What]ItemFactory{
var factories = map[What]ItemFactory{
{"ClusterRole"}: &clusterRoleFactory{},
{"ClusterRoleBinding"}: &clusterRoleBindingFactory{},
{"DaemonSet"}: &daemonSetFactory{},
@ -372,7 +376,7 @@ func (f *serviceAccountFactory) New() runtime.Object {
func (*serviceAccountFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.ServiceAccount)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.CoreV1().ServiceAccounts(f.Namespace.GetName())
if _, err := client.Create(item); err != nil {
@ -392,7 +396,7 @@ func (f *clusterRoleFactory) New() runtime.Object {
func (*clusterRoleFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.ClusterRole)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
Logf("Define cluster role %v", item.GetName())
@ -414,7 +418,7 @@ func (f *clusterRoleBindingFactory) New() runtime.Object {
func (*clusterRoleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.ClusterRoleBinding)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.RbacV1().ClusterRoleBindings()
@ -435,7 +439,7 @@ func (f *roleFactory) New() runtime.Object {
func (*roleFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.Role)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.RbacV1().Roles(f.Namespace.GetName())
@ -456,7 +460,7 @@ func (f *roleBindingFactory) New() runtime.Object {
func (*roleBindingFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*rbac.RoleBinding)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.RbacV1().RoleBindings(f.Namespace.GetName())
@ -477,7 +481,7 @@ func (f *serviceFactory) New() runtime.Object {
func (*serviceFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.Service)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.CoreV1().Services(f.Namespace.GetName())
@ -498,7 +502,7 @@ func (f *statefulSetFactory) New() runtime.Object {
func (*statefulSetFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*apps.StatefulSet)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.AppsV1().StatefulSets(f.Namespace.GetName())
@ -519,7 +523,7 @@ func (f *daemonSetFactory) New() runtime.Object {
func (*daemonSetFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*apps.DaemonSet)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.AppsV1().DaemonSets(f.Namespace.GetName())
@ -540,7 +544,7 @@ func (f *storageClassFactory) New() runtime.Object {
func (*storageClassFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*storage.StorageClass)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.StorageV1().StorageClasses()
@ -561,7 +565,7 @@ func (f *secretFactory) New() runtime.Object {
func (*secretFactory) Create(f *Framework, i interface{}) (func() error, error) {
item, ok := i.(*v1.Secret)
if !ok {
return nil, ItemNotSupported
return nil, errorItemNotSupported
}
client := f.ClientSet.CoreV1().Secrets(f.Namespace.GetName())