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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 Add test for fetching bundles #951

Merged
Merged
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
46 changes: 46 additions & 0 deletions internal/controllers/clusterextension_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"testing"

Expand All @@ -28,6 +29,7 @@ import (
"github.com/operator-framework/operator-controller/internal/conditionsets"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/pkg/features"
testutil "github.com/operator-framework/operator-controller/test/util"
)

// Describe: ClusterExtension Controller Test
Expand Down Expand Up @@ -1445,3 +1447,47 @@ var testBundleList = []*catalogmetadata.Bundle{
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
},
}

func TestClusterExtensionErrorGettingBundles(t *testing.T) {
ctx := context.Background()
fakeBundleProvider := testutil.NewFakeCatalogClientWithError(errors.New("fake-test-error"))
cl, reconciler := newClientAndReconciler(t, nil)
reconciler.BundleProvider = &fakeBundleProvider
extKey := types.NamespacedName{Name: fmt.Sprintf("cluster-extension-test-%s", rand.String(8))}

t.Log("Creating a test cluster extension object")
clusterExtension := &ocv1alpha1.ClusterExtension{
ObjectMeta: metav1.ObjectMeta{Name: extKey.Name},
Spec: ocv1alpha1.ClusterExtensionSpec{
PackageName: "prometheus",
InstallNamespace: "default",
},
}
require.NoError(t, cl.Create(ctx, clusterExtension))
defer func() {
require.NoError(t, cl.Delete(ctx, &ocv1alpha1.ClusterExtension{
ObjectMeta: metav1.ObjectMeta{Name: extKey.Name},
}))
}()
m1kola marked this conversation as resolved.
Show resolved Hide resolved

t.Log("Running reconcile")
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
require.Equal(t, ctrl.Result{}, res)
require.ErrorContains(t, err, "error fetching bundles: fake-test-error")

t.Log("Fetching updated cluster extension after reconcile")
require.NoError(t, cl.Get(ctx, extKey, clusterExtension))

t.Log("Checking the status fields")
require.Empty(t, clusterExtension.Status.ResolvedBundle)
require.Empty(t, clusterExtension.Status.InstalledBundle)

t.Log("Checking the expected conditions")
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
require.NotNil(t, cond)
require.Equal(t, metav1.ConditionFalse, cond.Status)
require.Equal(t, ocv1alpha1.ReasonResolutionFailed, cond.Reason)
require.Contains(t, cond.Message, "error fetching bundles: fake-test-error")

verifyInvariants(ctx, t, reconciler.Client, clusterExtension)
}
Loading