Skip to content

Commit 7af87c8

Browse files
committed
Fixed unittests
Signed-off-by: David Wertenteil <david.wertenteil@kaleido.io>
1 parent d830852 commit 7af87c8

14 files changed

+64
-203
lines changed

operator/internal/controller/besu_controller.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,9 @@ func (r *BesuReconciler) createPDB(ctx context.Context, node *corev1alpha1.Besu,
534534
setCondition(&node.Status.Conditions, corev1alpha1.ConditionPDB, metav1.ConditionTrue, corev1alpha1.ReasonPDBCreated, fmt.Sprintf("Name: %s", name))
535535
log.FromContext(ctx).Info("Created Besu pod disruption budget", "Name", name)
536536
} else if err != nil {
537-
return nil, err
537+
return nil, err
538538
}
539539

540-
if err := r.Create(ctx, pdb); err != nil {
541-
return pdb, err
542-
}
543-
setCondition(&node.Status.Conditions, corev1alpha1.ConditionPDB, metav1.ConditionTrue, corev1alpha1.ReasonPDBCreated, fmt.Sprintf("Name: %s", name))
544540
return pdb, nil
545541
}
546542

operator/internal/controller/besu_controller_test.go

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -267,161 +267,6 @@ var _ = Describe("Besu Controller", func() {
267267
})
268268
})
269269

270-
// Context("Resource Deletion", func() {
271-
// It("Should clean up all associated resources", func() {
272-
// By("Reconciling the Besu resource")
273-
// _, err := besuReconciler.Reconcile(ctx, ctrl.Request{
274-
// NamespacedName: typeNamespacedName,
275-
// })
276-
// Expect(err).NotTo(HaveOccurred())
277-
278-
// By("Deleting the Besu resource")
279-
// err = k8sClient.Delete(ctx, besu)
280-
// Expect(err).NotTo(HaveOccurred())
281-
282-
// By("Ensuring associated resources are deleted")
283-
// // Define expected resource names based on unique resourceName
284-
// statefulSetName := generateBesuName(resourceName)
285-
// serviceName := generateBesuName(resourceName)
286-
// configMapName := generateBesuName(resourceName)
287-
// secretName := generateBesuIDSecretName(resourceName)
288-
// pdbName := generateBesuName(resourceName)
289-
290-
// Eventually(func() bool {
291-
// statefulSet := &appsv1.StatefulSet{}
292-
// err = k8sClient.Get(ctx, types.NamespacedName{
293-
// Name: statefulSetName,
294-
// Namespace: namespace,
295-
// }, statefulSet)
296-
// return client.IgnoreNotFound(err) == nil
297-
// }, time.Second*5, time.Millisecond*500).Should(BeFalse())
298-
299-
// Eventually(func() bool {
300-
// service := &corev1.Service{}
301-
// err = k8sClient.Get(ctx, types.NamespacedName{
302-
// Name: serviceName,
303-
// Namespace: namespace,
304-
// }, service)
305-
// return client.IgnoreNotFound(err) == nil
306-
// }, time.Second*5, time.Millisecond*500).Should(BeFalse())
307-
308-
// Eventually(func() bool {
309-
// configMap := &corev1.ConfigMap{}
310-
// err = k8sClient.Get(ctx, types.NamespacedName{
311-
// Name: configMapName,
312-
// Namespace: namespace,
313-
// }, configMap)
314-
// return client.IgnoreNotFound(err) == nil
315-
// }, time.Second*5, time.Millisecond*500).Should(BeFalse())
316-
317-
// Eventually(func() bool {
318-
// secret := &corev1.Secret{}
319-
// err = k8sClient.Get(ctx, types.NamespacedName{
320-
// Name: secretName,
321-
// Namespace: namespace,
322-
// }, secret)
323-
// return client.IgnoreNotFound(err) == nil
324-
// }, time.Second*5, time.Millisecond*500).Should(BeFalse())
325-
326-
// Eventually(func() bool {
327-
// pdb := &policyv1.PodDisruptionBudget{}
328-
// err = k8sClient.Get(ctx, types.NamespacedName{
329-
// Name: pdbName,
330-
// Namespace: namespace,
331-
// }, pdb)
332-
// return client.IgnoreNotFound(err) == nil
333-
// }, time.Second*5, time.Millisecond*500).Should(BeFalse())
334-
// })
335-
// })
336-
337-
// Context("Error Scenarios", func() {
338-
// It("Should set the status to Pending and requeue when Genesis is missing", func() {
339-
// By("Setting a non-existent Genesis in the Besu resource")
340-
// updatedBesu := &corev1alpha1.Besu{}
341-
// err := k8sClient.Get(ctx, typeNamespacedName, updatedBesu)
342-
// Expect(err).NotTo(HaveOccurred())
343-
// updatedBesu.Spec.Genesis = "non-existent-genesis"
344-
// err = k8sClient.Update(ctx, updatedBesu)
345-
// Expect(err).NotTo(HaveOccurred())
346-
347-
// By("Reconciling the Besu resource")
348-
// result, err := besuReconciler.Reconcile(ctx, ctrl.Request{
349-
// NamespacedName: typeNamespacedName,
350-
// })
351-
// Expect(err).NotTo(HaveOccurred())
352-
// Expect(result.RequeueAfter).To(BeNumerically(">", 0))
353-
354-
// By("Verifying the status is set to Pending")
355-
// updatedBesu = &corev1alpha1.Besu{}
356-
// err = k8sClient.Get(ctx, typeNamespacedName, updatedBesu)
357-
// Expect(err).NotTo(HaveOccurred())
358-
// Expect(updatedBesu.Status.Phase).To(Equal(corev1alpha1.StatusPhasePending))
359-
// })
360-
361-
// It("Should set the status to Failed when resource creation fails", func() {
362-
// By("Providing invalid Service configuration")
363-
// updatedBesu := &corev1alpha1.Besu{}
364-
// err := k8sClient.Get(ctx, typeNamespacedName, updatedBesu)
365-
// Expect(err).NotTo(HaveOccurred())
366-
// updatedBesu.Spec.Service = corev1.ServiceSpec{
367-
// Type: corev1.ServiceType("InvalidType"),
368-
// }
369-
// err = k8sClient.Update(ctx, updatedBesu)
370-
// Expect(err).NotTo(HaveOccurred())
371-
372-
// By("Reconciling the Besu resource")
373-
// _, err = besuReconciler.Reconcile(ctx, ctrl.Request{
374-
// NamespacedName: typeNamespacedName,
375-
// })
376-
// Expect(err).To(HaveOccurred())
377-
378-
// By("Verifying the status is set to Failed")
379-
// updatedBesu = &corev1alpha1.Besu{}
380-
// err = k8sClient.Get(ctx, typeNamespacedName, updatedBesu)
381-
// Expect(err).NotTo(HaveOccurred())
382-
// Expect(updatedBesu.Status.Phase).To(Equal(corev1alpha1.StatusPhaseFailed))
383-
// })
384-
// })
385-
386-
// Context("Label and Annotation Updates", func() {
387-
// It("Should propagate labels and annotations to associated resources", func() {
388-
// By("Reconciling the Besu resource")
389-
// _, err := besuReconciler.Reconcile(ctx, ctrl.Request{
390-
// NamespacedName: typeNamespacedName,
391-
// })
392-
// Expect(err).NotTo(HaveOccurred())
393-
394-
// By("Updating labels and annotations in the Besu resource")
395-
// updatedBesu := &corev1alpha1.Besu{}
396-
// err = k8sClient.Get(ctx, typeNamespacedName, updatedBesu)
397-
// Expect(err).NotTo(HaveOccurred())
398-
// updatedBesu.Labels = map[string]string{
399-
// "new-label": "new-value",
400-
// }
401-
// updatedBesu.Annotations = map[string]string{
402-
// "new-annotation": "new-value",
403-
// }
404-
// err = k8sClient.Update(ctx, updatedBesu)
405-
// Expect(err).NotTo(HaveOccurred())
406-
407-
// By("Reconciling the Besu resource after label update")
408-
// _, err = besuReconciler.Reconcile(ctx, ctrl.Request{
409-
// NamespacedName: typeNamespacedName,
410-
// })
411-
// Expect(err).NotTo(HaveOccurred())
412-
413-
// By("Verifying labels are updated on the StatefulSet")
414-
// statefulSet := &appsv1.StatefulSet{}
415-
// err = k8sClient.Get(ctx, types.NamespacedName{
416-
// Name: generateBesuName(resourceName),
417-
// Namespace: namespace,
418-
// }, statefulSet)
419-
// Expect(err).NotTo(HaveOccurred())
420-
// Expect(statefulSet.Labels).To(HaveKeyWithValue("new-label", "new-value"))
421-
// Expect(statefulSet.Spec.Template.Annotations).To(HaveKeyWithValue("new-annotation", "new-value"))
422-
// })
423-
// })
424-
425270
Context("ConfigMap Changes", func() {
426271
It("Should trigger a rolling update of the StatefulSet when ConfigMap data changes", func() {
427272
By("Reconciling the Besu resource")

operator/internal/controller/inflight_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import (
1010
)
1111

1212
func TestNewInFlight(t *testing.T) {
13-
inflight := NewInFlight()
13+
inflight := NewInFlight(30 * time.Second)
1414
require.NotNil(t, inflight)
1515
require.NotNil(t, inflight.mux)
1616
require.NotNil(t, inflight.inFlight)
1717
assert.Equal(t, 30*time.Second, inflight.changeWaitDuration)
1818
}
1919

2020
func TestInFlight_Insert(t *testing.T) {
21-
inflight := NewInFlight()
21+
inflight := NewInFlight(1 * time.Second)
2222
key := "testKey"
2323

2424
// Insert a new key
@@ -31,7 +31,7 @@ func TestInFlight_Insert(t *testing.T) {
3131
}
3232

3333
func TestInFlight_IsQueued(t *testing.T) {
34-
inflight := NewInFlight()
34+
inflight := NewInFlight(1 * time.Second)
3535
key := "testKey"
3636

3737
// Key should not be queued initially
@@ -47,7 +47,7 @@ func TestInFlight_IsQueued(t *testing.T) {
4747
}
4848

4949
func TestInFlight_IsReady(t *testing.T) {
50-
inflight := NewInFlight()
50+
inflight := NewInFlight(1 * time.Second)
5151
key := "testKey"
5252
inflight.changeWaitDuration = 1 * time.Second
5353

@@ -78,7 +78,7 @@ func TestInFlight_IsReady(t *testing.T) {
7878
}
7979

8080
func TestInFlight_Delete(t *testing.T) {
81-
inflight := NewInFlight()
81+
inflight := NewInFlight(1 * time.Second)
8282
key := "testKey"
8383

8484
// Insert the key
@@ -97,7 +97,7 @@ func TestInFlight_Delete(t *testing.T) {
9797
}
9898

9999
func TestInFlight_Delete_NonExistentKey(t *testing.T) {
100-
inflight := NewInFlight()
100+
inflight := NewInFlight(1 * time.Second)
101101
key := "nonExistentKey"
102102

103103
// Delete a non-existent key (should not cause panic)
@@ -109,7 +109,7 @@ func TestInFlight_Delete_NonExistentKey(t *testing.T) {
109109
}
110110

111111
func TestInFlight_ConcurrentAccess(t *testing.T) {
112-
inflight := NewInFlight()
112+
inflight := NewInFlight(1 * time.Second)
113113
key := "testKey"
114114
var wg sync.WaitGroup
115115

@@ -159,7 +159,7 @@ func TestInFlight_ConcurrentAccess(t *testing.T) {
159159
}
160160

161161
func TestInFlight_InsertMultipleKeys(t *testing.T) {
162-
inflight := NewInFlight()
162+
inflight := NewInFlight(1 * time.Second)
163163
keys := []string{"key1", "key2", "key3"}
164164
inflight.changeWaitDuration = 1 * time.Second
165165

@@ -186,7 +186,7 @@ func TestInFlight_InsertMultipleKeys(t *testing.T) {
186186
}
187187

188188
func TestInFlight_IsReady_NoEntries(t *testing.T) {
189-
inflight := NewInFlight()
189+
inflight := NewInFlight(1 * time.Second)
190190
key := "nonExistentKey"
191191

192192
// IsReady should return false for a key that was never inserted
@@ -195,7 +195,7 @@ func TestInFlight_IsReady_NoEntries(t *testing.T) {
195195
}
196196

197197
func TestInFlight_IsQueued_NoEntries(t *testing.T) {
198-
inflight := NewInFlight()
198+
inflight := NewInFlight(1 * time.Second)
199199
key := "nonExistentKey"
200200

201201
// IsQueued should return false for a key that was never inserted

operator/internal/controller/paladin_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"context"
2121
"testing"
22+
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
2425
. "github.com/onsi/gomega"
@@ -412,7 +413,7 @@ func setupTestReconciler(objs ...client.Object) (*PaladinReconciler, client.Clie
412413
Client: client,
413414
Scheme: scheme,
414415
config: cfg,
415-
Changes: NewInFlight(),
416+
Changes: NewInFlight(1 * time.Second),
416417
}
417418

418419
return reconciler, client, nil

operator/internal/controller/paladindomain_controller_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestPaladinDomainReconcile_NewResource(t *testing.T) {
147147

148148
result, err := r.Reconcile(ctx, req)
149149
require.NoError(t, err)
150-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
150+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
151151

152152
// Fetch the updated domain
153153
updatedDomain := &corev1alpha1.PaladinDomain{}
@@ -190,7 +190,7 @@ func TestPaladinDomainReconcile_WithRegistryAddress(t *testing.T) {
190190
// First reconcile: set status to Pending
191191
result, err := r.Reconcile(ctx, req)
192192
require.NoError(t, err)
193-
require.Equal(t, ctrl.Result{Requeue: true}, result)
193+
require.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
194194

195195
// Fetch the updated domain
196196
updatedDomain := &corev1alpha1.PaladinDomain{}
@@ -201,7 +201,7 @@ func TestPaladinDomainReconcile_WithRegistryAddress(t *testing.T) {
201201
// Second reconcile: set status to Available
202202
result, err = r.Reconcile(ctx, req)
203203
require.NoError(t, err)
204-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
204+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
205205

206206
// Fetch the updated domain
207207
err = r.Get(ctx, req.NamespacedName, updatedDomain)
@@ -229,7 +229,7 @@ func TestUpdateStatusAndRequeue(t *testing.T) {
229229
domain.Status.Status = corev1alpha1.DomainStatusAvailable
230230
result, err := r.updateStatusAndRequeue(ctx, domain)
231231
require.NoError(t, err)
232-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
232+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
233233

234234
// Fetch the updated domain
235235
updatedDomain := &corev1alpha1.PaladinDomain{}
@@ -317,7 +317,7 @@ func TestTrackContractDeploymentAndRequeue_SuccessfulDeployment(t *testing.T) {
317317

318318
result, err := r.trackContractDeploymentAndRequeue(ctx, domain)
319319
require.NoError(t, err)
320-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
320+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
321321

322322
// Fetch the updated domain
323323
updatedDomain := &corev1alpha1.PaladinDomain{}
@@ -359,10 +359,10 @@ func TestPaladinDomainReconcile_MissingFields(t *testing.T) {
359359
// First reconcile: set status to Pending
360360
result, err := r.Reconcile(ctx, req)
361361
require.NoError(t, err)
362-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
362+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
363363

364364
// Second reconcile: should return error due to missing fields
365-
result, err = r.Reconcile(ctx, req)
365+
_, err = r.Reconcile(ctx, req)
366366
assert.Error(t, err)
367367
assert.Contains(t, err.Error(), "missing registryAddress or smartContractDeployment")
368368
}

operator/internal/controller/paladinregistration_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,23 @@ func (r *PaladinRegistrationReconciler) Reconcile(ctx context.Context, req ctrl.
151151
// log.Info(err, "Failed to reconcile transport transaction", "transport", transportName)
152152
requeueAfter = 100 * time.Millisecond // retry
153153
continue
154-
} else if regTx.statusChanged {
154+
} else if regTx.isStatusChanged() {
155155
reg.Status.PublishTxs[transportName] = transportPublishStatus
156156
if transportPublishStatus.TransactionStatus == corev1alpha1.TransactionStatusSuccess {
157157
log.Info("Transaction succeeded", "transport", transportName)
158158
publishCount++
159159
}
160160
changed = true
161-
} else if regTx.failed {
161+
} else if regTx.isFailed() {
162162
// what if one transaction failed and the other succeeded?
163163
// continue to try the other transactions
164164
log.Error(fmt.Errorf("transaction failed"), "transport", transportName)
165165
// if transaction failed do not requeue
166166
continue
167-
} else if !regTx.succeeded {
167+
} else if !regTx.isSucceeded() {
168168
// wait before requeueing
169169
requeueAfter = 5 * time.Second
170-
} else if regTx.succeeded {
170+
} else if regTx.isSucceeded() {
171171
log.Info("Transaction succeeded", "transport", transportName)
172172
}
173173
}

operator/internal/controller/paladinregistration_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"context"
2121
"fmt"
22+
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
2425
. "github.com/onsi/gomega"
@@ -203,7 +204,7 @@ func TestUpdateRegistrationStatusAndRequeue(t *testing.T) {
203204
reg.Status.PublishCount = 2
204205
result, err := reconciler.updateStatusAndRequeue(ctx, reg, reg.Status.PublishCount)
205206
require.NoError(t, err)
206-
assert.Equal(t, ctrl.Result{Requeue: true}, result)
207+
assert.Equal(t, ctrl.Result{Requeue: false, RequeueAfter: 50 * time.Millisecond}, result)
207208

208209
// Fetch the updated registration
209210
updatedReg := &corev1alpha1.PaladinRegistration{}

0 commit comments

Comments
 (0)