Skip to content

Commit c5e5747

Browse files
Adding unit tests for catalog availability
This is a follow-up from the previous PR #421 i.e. commit d320249 Signed-off-by: Lalatendu Mohanty <[email protected]>
1 parent 7040ee2 commit c5e5747

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

internal/catalogd/controllers/core/clustercatalog_controller_test.go

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,165 @@ func TestCatalogdControllerReconcile(t *testing.T) {
687687
},
688688
},
689689
},
690+
{
691+
name: "after catalog availability set to enable, finalizer should be added",
692+
puller: &imageutil.MockPuller{
693+
ImageFS: &fstest.MapFS{},
694+
},
695+
store: &MockStore{},
696+
catalog: &catalogdv1.ClusterCatalog{
697+
ObjectMeta: metav1.ObjectMeta{
698+
Name: "catalog",
699+
Finalizers: []string{},
700+
},
701+
Spec: catalogdv1.ClusterCatalogSpec{
702+
Source: catalogdv1.CatalogSource{
703+
Type: catalogdv1.SourceTypeImage,
704+
Image: &catalogdv1.ImageSource{
705+
Ref: "my.org/someimage:latest",
706+
},
707+
},
708+
AvailabilityMode: catalogdv1.AvailabilityModeAvailable,
709+
},
710+
Status: catalogdv1.ClusterCatalogStatus{
711+
URLs: &catalogdv1.ClusterCatalogURLs{Base: "URL"},
712+
ResolvedSource: &catalogdv1.ResolvedCatalogSource{
713+
Type: catalogdv1.SourceTypeImage,
714+
Image: &catalogdv1.ResolvedImageSource{
715+
Ref: "",
716+
},
717+
},
718+
Conditions: []metav1.Condition{
719+
{
720+
Type: catalogdv1.TypeServing,
721+
Status: metav1.ConditionFalse,
722+
Reason: catalogdv1.ReasonUnavailable,
723+
},
724+
{
725+
Type: catalogdv1.TypeProgressing,
726+
Status: metav1.ConditionFalse,
727+
Reason: catalogdv1.ReasonUserSpecifiedUnavailable,
728+
},
729+
},
730+
},
731+
},
732+
expectedCatalog: &catalogdv1.ClusterCatalog{
733+
ObjectMeta: metav1.ObjectMeta{
734+
Name: "catalog",
735+
Finalizers: []string{fbcDeletionFinalizer},
736+
},
737+
Spec: catalogdv1.ClusterCatalogSpec{
738+
Source: catalogdv1.CatalogSource{
739+
Type: catalogdv1.SourceTypeImage,
740+
Image: &catalogdv1.ImageSource{
741+
Ref: "my.org/someimage:latest",
742+
},
743+
},
744+
AvailabilityMode: catalogdv1.AvailabilityModeAvailable,
745+
},
746+
Status: catalogdv1.ClusterCatalogStatus{
747+
URLs: &catalogdv1.ClusterCatalogURLs{Base: "URL"},
748+
ResolvedSource: &catalogdv1.ResolvedCatalogSource{
749+
Type: catalogdv1.SourceTypeImage,
750+
Image: &catalogdv1.ResolvedImageSource{
751+
Ref: "",
752+
},
753+
},
754+
Conditions: []metav1.Condition{
755+
{
756+
Type: catalogdv1.TypeServing,
757+
Status: metav1.ConditionFalse,
758+
Reason: catalogdv1.ReasonUnavailable,
759+
},
760+
{
761+
Type: catalogdv1.TypeProgressing,
762+
Status: metav1.ConditionFalse,
763+
Reason: catalogdv1.ReasonUserSpecifiedUnavailable,
764+
},
765+
},
766+
},
767+
},
768+
},
769+
{
770+
name: "after catalog availability set to enable and finalizer added, the status should get updated",
771+
puller: &imageutil.MockPuller{
772+
ImageFS: &fstest.MapFS{},
773+
},
774+
store: &MockStore{},
775+
catalog: &catalogdv1.ClusterCatalog{
776+
ObjectMeta: metav1.ObjectMeta{
777+
Name: "catalog",
778+
Finalizers: []string{fbcDeletionFinalizer},
779+
},
780+
Spec: catalogdv1.ClusterCatalogSpec{
781+
Source: catalogdv1.CatalogSource{
782+
Type: catalogdv1.SourceTypeImage,
783+
Image: &catalogdv1.ImageSource{
784+
Ref: "my.org/someimage:latest",
785+
},
786+
},
787+
AvailabilityMode: catalogdv1.AvailabilityModeAvailable,
788+
},
789+
Status: catalogdv1.ClusterCatalogStatus{
790+
URLs: &catalogdv1.ClusterCatalogURLs{Base: "URL"},
791+
LastUnpacked: &metav1.Time{},
792+
ResolvedSource: &catalogdv1.ResolvedCatalogSource{
793+
Type: catalogdv1.SourceTypeImage,
794+
Image: &catalogdv1.ResolvedImageSource{
795+
Ref: "my.org/someimage:latest",
796+
},
797+
},
798+
Conditions: []metav1.Condition{
799+
{
800+
Type: catalogdv1.TypeServing,
801+
Status: metav1.ConditionFalse,
802+
Reason: catalogdv1.ReasonUnavailable,
803+
},
804+
{
805+
Type: catalogdv1.TypeProgressing,
806+
Status: metav1.ConditionFalse,
807+
Reason: catalogdv1.ReasonUserSpecifiedUnavailable,
808+
},
809+
},
810+
},
811+
},
812+
expectedCatalog: &catalogdv1.ClusterCatalog{
813+
ObjectMeta: metav1.ObjectMeta{
814+
Name: "catalog",
815+
Finalizers: []string{fbcDeletionFinalizer},
816+
},
817+
Spec: catalogdv1.ClusterCatalogSpec{
818+
Source: catalogdv1.CatalogSource{
819+
Type: catalogdv1.SourceTypeImage,
820+
Image: &catalogdv1.ImageSource{
821+
Ref: "my.org/someimage:latest",
822+
},
823+
},
824+
AvailabilityMode: catalogdv1.AvailabilityModeAvailable,
825+
},
826+
Status: catalogdv1.ClusterCatalogStatus{
827+
URLs: &catalogdv1.ClusterCatalogURLs{Base: "URL"},
828+
ResolvedSource: &catalogdv1.ResolvedCatalogSource{
829+
Type: catalogdv1.SourceTypeImage,
830+
Image: &catalogdv1.ResolvedImageSource{
831+
Ref: "my.org/someimage:latest",
832+
},
833+
},
834+
Conditions: []metav1.Condition{
835+
{
836+
Type: catalogdv1.TypeServing,
837+
Status: metav1.ConditionTrue,
838+
Reason: catalogdv1.ReasonAvailable,
839+
},
840+
{
841+
Type: catalogdv1.TypeProgressing,
842+
Status: metav1.ConditionTrue,
843+
Reason: catalogdv1.ReasonSucceeded,
844+
},
845+
},
846+
},
847+
},
848+
},
690849
} {
691850
t.Run(tt.name, func(t *testing.T) {
692851
reconciler := &ClusterCatalogReconciler{

0 commit comments

Comments
 (0)