@@ -3,6 +3,7 @@ package controllers_test
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "testing"
89
@@ -28,6 +29,7 @@ import (
2829 "github.com/operator-framework/operator-controller/internal/conditionsets"
2930 "github.com/operator-framework/operator-controller/internal/controllers"
3031 "github.com/operator-framework/operator-controller/pkg/features"
32+ testutil "github.com/operator-framework/operator-controller/test/util"
3133)
3234
3335// Describe: ClusterExtension Controller Test
@@ -1445,3 +1447,47 @@ var testBundleList = []*catalogmetadata.Bundle{
14451447 InChannels : []* catalogmetadata.Channel {& prometheusBetaChannel },
14461448 },
14471449}
1450+
1451+ func TestClusterExtensionErrorGettingBundles (t * testing.T ) {
1452+ ctx := context .Background ()
1453+ fakeBundleProvider := testutil .NewFakeCatalogClientWithError (errors .New ("fake-test-error" ))
1454+ cl , reconciler := newClientAndReconciler (t , nil )
1455+ reconciler .BundleProvider = & fakeBundleProvider
1456+ extKey := types.NamespacedName {Name : fmt .Sprintf ("cluster-extension-test-%s" , rand .String (8 ))}
1457+
1458+ t .Log ("Creating a test cluster extension object" )
1459+ clusterExtension := & ocv1alpha1.ClusterExtension {
1460+ ObjectMeta : metav1.ObjectMeta {Name : extKey .Name },
1461+ Spec : ocv1alpha1.ClusterExtensionSpec {
1462+ PackageName : "prometheus" ,
1463+ InstallNamespace : "default" ,
1464+ },
1465+ }
1466+ require .NoError (t , cl .Create (ctx , clusterExtension ))
1467+ defer func () {
1468+ require .NoError (t , cl .Delete (ctx , & ocv1alpha1.ClusterExtension {
1469+ ObjectMeta : metav1.ObjectMeta {Name : extKey .Name },
1470+ }))
1471+ }()
1472+
1473+ t .Log ("Running reconcile" )
1474+ res , err := reconciler .Reconcile (ctx , ctrl.Request {NamespacedName : extKey })
1475+ require .Equal (t , ctrl.Result {}, res )
1476+ require .ErrorContains (t , err , "error fetching bundles: fake-test-error" )
1477+
1478+ t .Log ("Fetching updated cluster extension after reconcile" )
1479+ require .NoError (t , cl .Get (ctx , extKey , clusterExtension ))
1480+
1481+ t .Log ("Checking the status fields" )
1482+ require .Empty (t , clusterExtension .Status .ResolvedBundle )
1483+ require .Empty (t , clusterExtension .Status .InstalledBundle )
1484+
1485+ t .Log ("Checking the expected conditions" )
1486+ cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1alpha1 .TypeResolved )
1487+ require .NotNil (t , cond )
1488+ require .Equal (t , metav1 .ConditionFalse , cond .Status )
1489+ require .Equal (t , ocv1alpha1 .ReasonResolutionFailed , cond .Reason )
1490+ require .Contains (t , cond .Message , "error fetching bundles: fake-test-error" )
1491+
1492+ verifyInvariants (ctx , t , reconciler .Client , clusterExtension )
1493+ }
0 commit comments