-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to use EventPolicy helper functions from reconciler/testing …
…package
- Loading branch information
Showing
3 changed files
with
144 additions
and
49 deletions.
There are no files selected for viewing
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
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,104 @@ | ||
/* | ||
Check failure on line 1 in pkg/reconciler/testing/v1/eventpolicy.go GitHub Actions / style / Golang / Auto-format and Check
|
||
Copyright 2024 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package testing | ||
|
||
import ( | ||
"context" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"knative.dev/eventing/pkg/apis/eventing/v1alpha1" | ||
"knative.dev/pkg/apis" | ||
) | ||
|
||
// EventPolicyOption enables further configuration of an EventPolicy. | ||
type EventPolicyOption func(*v1alpha1.EventPolicy) | ||
|
||
// NewEventPolicy creates a EventPolicy with EventPolicyOptions. | ||
func NewEventPolicy(name, namespace string, o ...EventPolicyOption) *v1alpha1.EventPolicy { | ||
ep := &v1alpha1.EventPolicy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: namespace, | ||
Name: name, | ||
}, | ||
} | ||
for _, opt := range o { | ||
opt(ep) | ||
} | ||
ep.SetDefaults(context.Background()) | ||
|
||
return ep | ||
} | ||
|
||
func WithInitEventPolicyConditions(et *v1alpha1.EventPolicy) { | ||
et.Status.InitializeConditions() | ||
} | ||
|
||
func WithReadyEventPolicyCondition(ep *v1alpha1.EventPolicy) { | ||
ep.Status.Conditions = []apis.Condition{ | ||
{ | ||
Type: v1alpha1.EventPolicyConditionReady, | ||
Status: corev1.ConditionTrue, | ||
}, | ||
} | ||
} | ||
|
||
func WithUnreadyEventPolicyCondition(ep *v1alpha1.EventPolicy) { | ||
ep.Status.Conditions = []apis.Condition{ | ||
{ | ||
Type: v1alpha1.EventPolicyConditionReady, | ||
Status: corev1.ConditionFalse, | ||
}, | ||
} | ||
} | ||
|
||
func WithEventPolicyTo(tos ...v1alpha1.EventPolicySpecTo) EventPolicyOption { | ||
return func(ep *v1alpha1.EventPolicy) { | ||
for _, to := range tos { | ||
ep.Spec.To = append(ep.Spec.To, to) | ||
} | ||
} | ||
} | ||
|
||
func WithEventPolicyToRef(ref v1alpha1.EventPolicyToReference) EventPolicyOption { | ||
return func(ep *v1alpha1.EventPolicy) { | ||
ep.Spec.To = append(ep.Spec.To, v1alpha1.EventPolicySpecTo{ | ||
Ref: &ref, | ||
}) | ||
} | ||
} | ||
|
||
func WithEventPolicyFrom(froms ...v1alpha1.EventPolicySpecFrom) EventPolicyOption { | ||
return func(ep *v1alpha1.EventPolicy) { | ||
for _, from := range froms { | ||
ep.Spec.From = append(ep.Spec.From, from) | ||
} | ||
} | ||
} | ||
|
||
func WithEventPolicyLabels(labels map[string]string) EventPolicyOption { | ||
return func(ep *v1alpha1.EventPolicy) { | ||
ep.ObjectMeta.Labels = labels | ||
} | ||
} | ||
|
||
func WithEventPolicyOwnerReference(ownerRef metav1.OwnerReference) EventPolicyOption { | ||
return func(ep *v1alpha1.EventPolicy) { | ||
ep.ObjectMeta.OwnerReferences = []metav1.OwnerReference{ | ||
ownerRef, | ||
} | ||
} | ||
} |
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