Skip to content

Commit

Permalink
test: fix tests for subscriptions create/update
Browse files Browse the repository at this point in the history
Signed-off-by: Nitin Goyal <[email protected]>
  • Loading branch information
iamniting committed Nov 14, 2024
1 parent 08fba70 commit 8ce7d31
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions controllers/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

Expand Down Expand Up @@ -60,6 +61,9 @@ func TestEnsureSubscription(t *testing.T) {
for _, subscription := range subs {
sub := subscription.DeepCopy()
sub.Spec.Channel = "fake-channel"
// Set the creation timestamp to a non-zero value to simulate that the subscription already exists
// This is required because the fake client does not set the creation timestamp
sub.CreationTimestamp = metav1.Now()
err = fakeReconciler.Client.Create(context.TODO(), sub)
assert.NoError(t, err)
}
Expand Down Expand Up @@ -101,10 +105,27 @@ func TestEnsureSubscription(t *testing.T) {
}

actualSubscription := &operatorv1alpha1.Subscription{}
err = fakeReconciler.Client.Get(context.TODO(), types.NamespacedName{Name: expectedSubscription.Name, Namespace: expectedSubscription.Namespace}, actualSubscription)
assert.NoError(t, err)

assert.Equal(t, expectedSubscription.Spec, actualSubscription.Spec)
err = fakeReconciler.Client.Get(context.TODO(),
types.NamespacedName{Name: expectedSubscription.Name, Namespace: expectedSubscription.Namespace}, actualSubscription)

// create case
if !tc.subscriptionAlreadyExist {
if expectedSubscription.Spec.Package == OdfDepsSubscriptionPackage {
assert.NoError(t, err)
// Set odf-dependencies catalog and catalog namespace same as odf-operator in expected subscription
// That is what being set by controller and verify the same
expectedSubscription.Spec.CatalogSource = odfSub.Spec.CatalogSource
expectedSubscription.Spec.CatalogSourceNamespace = odfSub.Spec.CatalogSourceNamespace
assert.Equal(t, expectedSubscription.Spec, actualSubscription.Spec)
} else {
assert.Error(t, err)
assert.True(t, errors.IsNotFound(err))
}
// update case
} else if tc.subscriptionAlreadyExist {
assert.NoError(t, err)
assert.Equal(t, expectedSubscription.Spec, actualSubscription.Spec)
}
}
}
}
Expand Down

0 comments on commit 8ce7d31

Please sign in to comment.