Skip to content
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

✨ Adding tests for catalog availability #436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions internal/controllers/core/clustercatalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,172 @@ func TestCatalogdControllerReconcile(t *testing.T) {
},
},
},
{
name: "after catalog availability set to enable, finalizer should be added",
source: &MockSource{
result: &source.Result{
State: source.StateUnpacked,
FS: &fstest.MapFS{},
},
},
store: &MockStore{},
catalog: &catalogdv1alpha1.ClusterCatalog{
ObjectMeta: metav1.ObjectMeta{
Name: "catalog",
Finalizers: []string{},
},
Spec: catalogdv1alpha1.ClusterCatalogSpec{
Source: catalogdv1alpha1.CatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ImageSource{
Ref: "my.org/someimage:latest",
},
},
Availability: "Enabled",
},
Status: catalogdv1alpha1.ClusterCatalogStatus{
URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"},
LastUnpacked: metav1.Time{},
ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ResolvedImageSource{
Ref: "",
},
},
Conditions: []metav1.Condition{
{
Type: catalogdv1alpha1.TypeServing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonUnavailable,
},
{
Type: catalogdv1alpha1.TypeProgressing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonDisabled,
},
},
},
},
expectedCatalog: &catalogdv1alpha1.ClusterCatalog{
ObjectMeta: metav1.ObjectMeta{
Name: "catalog",
Finalizers: []string{fbcDeletionFinalizer},
},
Spec: catalogdv1alpha1.ClusterCatalogSpec{
Source: catalogdv1alpha1.CatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ImageSource{
Ref: "my.org/someimage:latest",
},
},
Availability: "Enabled",
},
Status: catalogdv1alpha1.ClusterCatalogStatus{
URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"},
ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ResolvedImageSource{
Ref: "",
},
},
Conditions: []metav1.Condition{
{
Type: catalogdv1alpha1.TypeServing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonUnavailable,
},
{
Type: catalogdv1alpha1.TypeProgressing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonDisabled,
},
},
},
},
},
{
name: "after catalog availability set to enable and finalizer added, the status should get updated",
source: &MockSource{
result: &source.Result{
State: source.StateUnpacked,
FS: &fstest.MapFS{},
},
},
store: &MockStore{},
catalog: &catalogdv1alpha1.ClusterCatalog{
ObjectMeta: metav1.ObjectMeta{
Name: "catalog",
Finalizers: []string{fbcDeletionFinalizer},
},
Spec: catalogdv1alpha1.ClusterCatalogSpec{
Source: catalogdv1alpha1.CatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ImageSource{
Ref: "my.org/someimage:latest",
},
},
Availability: "Enabled",
},
Status: catalogdv1alpha1.ClusterCatalogStatus{
URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"},
LastUnpacked: metav1.Time{},
ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ResolvedImageSource{
Ref: "",
},
},
Conditions: []metav1.Condition{
{
Type: catalogdv1alpha1.TypeServing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonUnavailable,
},
{
Type: catalogdv1alpha1.TypeProgressing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonDisabled,
},
},
},
},
expectedCatalog: &catalogdv1alpha1.ClusterCatalog{
ObjectMeta: metav1.ObjectMeta{
Name: "catalog",
Finalizers: []string{fbcDeletionFinalizer},
},
Spec: catalogdv1alpha1.ClusterCatalogSpec{
Source: catalogdv1alpha1.CatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ImageSource{
Ref: "my.org/someimage:latest",
},
},
Availability: "Enabled",
},
Status: catalogdv1alpha1.ClusterCatalogStatus{
URLs: &catalogdv1alpha1.ClusterCatalogURLs{Base: "URL"},
ResolvedSource: &catalogdv1alpha1.ResolvedCatalogSource{
Type: catalogdv1alpha1.SourceTypeImage,
Image: &catalogdv1alpha1.ResolvedImageSource{
Ref: "",
},
},
Conditions: []metav1.Condition{
{
Type: catalogdv1alpha1.TypeServing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonUnavailable,
},
{
Type: catalogdv1alpha1.TypeProgressing,
Status: metav1.ConditionFalse,
Reason: catalogdv1alpha1.ReasonDisabled,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that the status would change but it is not changing which is weird.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first reconciliation after the Availability is changed back to Enabled is going to add the finalizers back here. The second reconciliation that'll happen AFTER the finalizer is added will be updating these conditions after finishing its job.

One way we can handle this is probably by breaking this test into two tests

  1. "ClusterCatalog previously disabled, is enabled back, finalizers are added back"
  2. "ClusterCatalog previously disabled, is enabled back, finalizers have been added back, status conditions updated to show Serving=True, Progressing=False (or whatever's appropriate)"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea. let me try that. Thanks.

},
},
},
},
},
} {
t.Run(tt.name, func(t *testing.T) {
reconciler := &ClusterCatalogReconciler{
Expand Down
Loading