Skip to content

Commit c96f4d8

Browse files
Mikalai Radchukperdasilva
Mikalai Radchuk
authored andcommitted
Updates unit tests for syncResolvingNamespace
Tests now include handling of unpacking errors Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 698e4d6 commit c96f4d8

File tree

2 files changed

+248
-59
lines changed

2 files changed

+248
-59
lines changed

Diff for: pkg/controller/operators/catalog/operator_test.go

+43-17
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import (
4949
"github.com/operator-framework/api/pkg/operators/v1alpha1"
5050
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
5151
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
52+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle"
53+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/bundle/bundlefakes"
5254
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
5355
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
5456
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
@@ -1127,6 +1129,12 @@ func TestSyncResolvingNamespace(t *testing.T) {
11271129
clockFake := utilclocktesting.NewFakeClock(time.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC))
11281130
now := metav1.NewTime(clockFake.Now())
11291131
testNamespace := "testNamespace"
1132+
og := &operatorsv1.OperatorGroup{
1133+
ObjectMeta: metav1.ObjectMeta{
1134+
Name: "og",
1135+
Namespace: testNamespace,
1136+
},
1137+
}
11301138

11311139
type fields struct {
11321140
clientOptions []clientfake.Option
@@ -1181,6 +1189,13 @@ func TestSyncResolvingNamespace(t *testing.T) {
11811189
Status: v1alpha1.SubscriptionStatus{
11821190
CurrentCSV: "",
11831191
State: "",
1192+
Conditions: []v1alpha1.SubscriptionCondition{
1193+
{
1194+
Type: v1alpha1.SubscriptionBundleUnpacking,
1195+
Status: corev1.ConditionFalse,
1196+
},
1197+
},
1198+
LastUpdated: now,
11841199
},
11851200
},
11861201
},
@@ -1319,7 +1334,7 @@ func TestSyncResolvingNamespace(t *testing.T) {
13191334
ctx, cancel := context.WithCancel(context.TODO())
13201335
defer cancel()
13211336

1322-
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withFakeClientOptions(tt.fields.clientOptions...))
1337+
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(append(tt.fields.existingOLMObjs, og)...), withFakeClientOptions(tt.fields.clientOptions...))
13231338
require.NoError(t, err)
13241339

13251340
o.reconciler = &fakes.FakeRegistryReconcilerFactory{
@@ -1560,17 +1575,18 @@ func fakeConfigMapData() map[string]string {
15601575

15611576
// fakeOperatorConfig is the configuration for a fake operator.
15621577
type fakeOperatorConfig struct {
1563-
clock utilclock.Clock
1564-
clientObjs []runtime.Object
1565-
k8sObjs []runtime.Object
1566-
extObjs []runtime.Object
1567-
regObjs []runtime.Object
1568-
clientOptions []clientfake.Option
1569-
logger *logrus.Logger
1570-
resolver resolver.StepResolver
1571-
recorder record.EventRecorder
1572-
reconciler reconciler.RegistryReconcilerFactory
1573-
sources []sourceAddress
1578+
clock utilclock.Clock
1579+
clientObjs []runtime.Object
1580+
k8sObjs []runtime.Object
1581+
extObjs []runtime.Object
1582+
regObjs []runtime.Object
1583+
clientOptions []clientfake.Option
1584+
logger *logrus.Logger
1585+
resolver resolver.StepResolver
1586+
recorder record.EventRecorder
1587+
reconciler reconciler.RegistryReconcilerFactory
1588+
bundleUnpacker bundle.Unpacker
1589+
sources []sourceAddress
15741590
}
15751591

15761592
// fakeOperatorOption applies an option to the given fake operator configuration.
@@ -1582,6 +1598,12 @@ func withResolver(res resolver.StepResolver) fakeOperatorOption {
15821598
}
15831599
}
15841600

1601+
func withBundleUnpacker(bundleUnpacker bundle.Unpacker) fakeOperatorOption {
1602+
return func(config *fakeOperatorConfig) {
1603+
config.bundleUnpacker = bundleUnpacker
1604+
}
1605+
}
1606+
15851607
func withSources(sources ...sourceAddress) fakeOperatorOption {
15861608
return func(config *fakeOperatorConfig) {
15871609
config.sources = sources
@@ -1627,10 +1649,11 @@ type sourceAddress struct {
16271649
func NewFakeOperator(ctx context.Context, namespace string, namespaces []string, fakeOptions ...fakeOperatorOption) (*Operator, error) {
16281650
// Apply options to default config
16291651
config := &fakeOperatorConfig{
1630-
logger: logrus.StandardLogger(),
1631-
clock: utilclock.RealClock{},
1632-
resolver: &fakes.FakeStepResolver{},
1633-
recorder: &record.FakeRecorder{},
1652+
logger: logrus.StandardLogger(),
1653+
clock: utilclock.RealClock{},
1654+
resolver: &fakes.FakeStepResolver{},
1655+
recorder: &record.FakeRecorder{},
1656+
bundleUnpacker: &bundlefakes.FakeUnpacker{},
16341657
}
16351658
for _, option := range fakeOptions {
16361659
option(config)
@@ -1669,12 +1692,14 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
16691692
subInformer := operatorsFactory.Operators().V1alpha1().Subscriptions()
16701693
ipInformer := operatorsFactory.Operators().V1alpha1().InstallPlans()
16711694
csvInformer := operatorsFactory.Operators().V1alpha1().ClusterServiceVersions()
1672-
sharedInformers = append(sharedInformers, catsrcInformer.Informer(), subInformer.Informer(), ipInformer.Informer(), csvInformer.Informer())
1695+
ogInformer := operatorsFactory.Operators().V1().OperatorGroups()
1696+
sharedInformers = append(sharedInformers, catsrcInformer.Informer(), subInformer.Informer(), ipInformer.Informer(), csvInformer.Informer(), ogInformer.Informer())
16731697

16741698
lister.OperatorsV1alpha1().RegisterCatalogSourceLister(metav1.NamespaceAll, catsrcInformer.Lister())
16751699
lister.OperatorsV1alpha1().RegisterSubscriptionLister(metav1.NamespaceAll, subInformer.Lister())
16761700
lister.OperatorsV1alpha1().RegisterInstallPlanLister(metav1.NamespaceAll, ipInformer.Lister())
16771701
lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(metav1.NamespaceAll, csvInformer.Lister())
1702+
lister.OperatorsV1().RegisterOperatorGroupLister(metav1.NamespaceAll, ogInformer.Lister())
16781703

16791704
factory := informers.NewSharedInformerFactoryWithOptions(opClientFake.KubernetesInterface(), wakeupInterval, informers.WithNamespace(metav1.NamespaceAll))
16801705
roleInformer := factory.Rbac().V1().Roles()
@@ -1722,6 +1747,7 @@ func NewFakeOperator(ctx context.Context, namespace string, namespaces []string,
17221747
recorder: config.recorder,
17231748
clientAttenuator: scoped.NewClientAttenuator(logger, &rest.Config{}, opClientFake),
17241749
serviceAccountQuerier: scoped.NewUserDefinedServiceAccountQuerier(logger, clientFake),
1750+
bundleUnpacker: config.bundleUnpacker,
17251751
catsrcQueueSet: queueinformer.NewEmptyResourceQueueSet(),
17261752
clientFactory: &stubClientFactory{
17271753
operatorClient: opClientFake,

0 commit comments

Comments
 (0)