-
Notifications
You must be signed in to change notification settings - Fork 68
Add additional unit-tests for Conditions #92
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
Changes from 1 commit
b0b532a
3bdac2d
dd5a951
2f6c579
9c9c1e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,13 +28,20 @@ type OperatorSpec struct { | |
| } | ||
|
|
||
| const ( | ||
| // TODO(user): add more Types | ||
| // TODO(user): add more Types, here and into GetTypes() | ||
| TypeReady = "Ready" | ||
|
|
||
| // TODO(user): add more Reasons | ||
| ReasonNotImplemented = "NotImplemented" | ||
| ) | ||
|
|
||
| func GetTypes() []string { | ||
| // TODO(user): add Types from above | ||
| return []string{ | ||
| TypeReady, | ||
| } | ||
| } | ||
|
||
|
|
||
| // OperatorStatus defines the observed state of Operator | ||
| type OperatorStatus struct { | ||
| // +patchMergeKey=type | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,15 +71,15 @@ func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c | |
| compareOp := reconciledOp.DeepCopy() | ||
| existingOp.Status, compareOp.Status = operatorsv1alpha1.OperatorStatus{}, operatorsv1alpha1.OperatorStatus{} | ||
| existingOp.Finalizers, compareOp.Finalizers = []string{}, []string{} | ||
| specDiffers := !equality.Semantic.DeepEqual(existingOp, compareOp) | ||
| unexpectedFieldsChanged := !equality.Semantic.DeepEqual(existingOp, compareOp) | ||
|
||
|
|
||
| if updateStatus { | ||
| if updateErr := r.Status().Update(ctx, reconciledOp); updateErr != nil { | ||
| return res, utilerrors.NewAggregate([]error{reconcileErr, updateErr}) | ||
| } | ||
| } | ||
|
|
||
| if specDiffers { | ||
| if unexpectedFieldsChanged { | ||
| panic("spec or metadata changed by reconciler") | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -127,7 +127,7 @@ var _ = Describe("Reconcile Test", func() { | |||||
| err = k8sClient.Delete(ctx, operator) | ||||||
| Expect(err).To(Not(HaveOccurred())) | ||||||
| }) | ||||||
| It("has a Condition created", func() { | ||||||
| It("has all Conditions created", func() { | ||||||
| getOperator := &operatorsv1alpha1.Operator{} | ||||||
|
|
||||||
| err = k8sClient.Get(ctx, client.ObjectKey{ | ||||||
|
|
@@ -138,7 +138,24 @@ var _ = Describe("Reconcile Test", func() { | |||||
| // There should always be a "Ready" condition, regardless of Status. | ||||||
| conds := getOperator.Status.Conditions | ||||||
| Expect(conds).To(Not(BeEmpty())) | ||||||
| Expect(conds).To(ContainElement(HaveField("Type", operatorsv1alpha1.TypeReady))) | ||||||
| types := operatorsv1alpha1.GetTypes() | ||||||
| Expect(conds).To(HaveLen(len(types))) | ||||||
| for _, t := range types { | ||||||
| Expect(conds).To(ContainElement(HaveField("Type", t))) | ||||||
awgreene marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| } | ||||||
| }) | ||||||
| It("has matching gnerations in Conditions", func() { | ||||||
|
||||||
| It("has matching gnerations in Conditions", func() { | |
| It("has matching generations in Conditions", func() { |
Outdated
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.
nit: HaveField doesn't give us compile-time checks on the field name, so its susceptible to typos, for example.
| Expect(c).To(HaveField("ObservedGeneration", getOperator.GetGeneration())) | |
| Expect(c.ObservedGeneration).To(Equal(getOperator.GetGeneration())) |
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 agree with you 100% if this were not test code. Test code, on the other hand, I could see it either way.
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 like this note.