Skip to content

Commit 3f598d5

Browse files
Mikalai Radchukm1kola
Mikalai Radchuk
authored andcommittedMar 27, 2023
Updates syncResolvingNamespace tests
* Makes `TestSyncResolvingNamespace` check the resulting subscription * Removes unused fields from `TestSyncSubscriptions` Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent e5da837 commit 3f598d5

File tree

2 files changed

+101
-22
lines changed

2 files changed

+101
-22
lines changed
 

‎pkg/controller/operators/catalog/operator_test.go

+93-10
Original file line numberDiff line numberDiff line change
@@ -1125,19 +1125,19 @@ func TestSyncCatalogSources(t *testing.T) {
11251125

11261126
func TestSyncResolvingNamespace(t *testing.T) {
11271127
clockFake := utilclocktesting.NewFakeClock(time.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC))
1128+
now := metav1.NewTime(clockFake.Now())
11281129
testNamespace := "testNamespace"
11291130

11301131
type fields struct {
1131-
clientOptions []clientfake.Option
1132-
sourcesLastUpdate metav1.Time
1133-
resolveErr error
1134-
existingOLMObjs []runtime.Object
1135-
existingObjects []runtime.Object
1132+
clientOptions []clientfake.Option
1133+
resolveErr error
1134+
existingOLMObjs []runtime.Object
11361135
}
11371136
tests := []struct {
1138-
name string
1139-
fields fields
1140-
wantErr error
1137+
name string
1138+
fields fields
1139+
wantSubscriptions []*v1alpha1.Subscription
1140+
wantErr error
11411141
}{
11421142
{
11431143
name: "NoError",
@@ -1164,6 +1164,26 @@ func TestSyncResolvingNamespace(t *testing.T) {
11641164
},
11651165
},
11661166
},
1167+
wantSubscriptions: []*v1alpha1.Subscription{
1168+
{
1169+
TypeMeta: metav1.TypeMeta{
1170+
Kind: v1alpha1.SubscriptionKind,
1171+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
1172+
},
1173+
ObjectMeta: metav1.ObjectMeta{
1174+
Name: "sub",
1175+
Namespace: testNamespace,
1176+
},
1177+
Spec: &v1alpha1.SubscriptionSpec{
1178+
CatalogSource: "src",
1179+
CatalogSourceNamespace: testNamespace,
1180+
},
1181+
Status: v1alpha1.SubscriptionStatus{
1182+
CurrentCSV: "",
1183+
State: "",
1184+
},
1185+
},
1186+
},
11671187
},
11681188
{
11691189
name: "NotSatisfiableError",
@@ -1196,6 +1216,35 @@ func TestSyncResolvingNamespace(t *testing.T) {
11961216
},
11971217
},
11981218
},
1219+
wantSubscriptions: []*v1alpha1.Subscription{
1220+
{
1221+
TypeMeta: metav1.TypeMeta{
1222+
Kind: v1alpha1.SubscriptionKind,
1223+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
1224+
},
1225+
ObjectMeta: metav1.ObjectMeta{
1226+
Name: "sub",
1227+
Namespace: testNamespace,
1228+
},
1229+
Spec: &v1alpha1.SubscriptionSpec{
1230+
CatalogSource: "src",
1231+
CatalogSourceNamespace: testNamespace,
1232+
},
1233+
Status: v1alpha1.SubscriptionStatus{
1234+
CurrentCSV: "",
1235+
State: "",
1236+
Conditions: []v1alpha1.SubscriptionCondition{
1237+
{
1238+
Type: v1alpha1.SubscriptionResolutionFailed,
1239+
Reason: "ConstraintsNotSatisfiable",
1240+
Message: "constraints not satisfiable: something",
1241+
Status: corev1.ConditionTrue,
1242+
},
1243+
},
1244+
LastUpdated: now,
1245+
},
1246+
},
1247+
},
11991248
},
12001249
{
12011250
name: "OtherError",
@@ -1232,6 +1281,35 @@ func TestSyncResolvingNamespace(t *testing.T) {
12321281
},
12331282
resolveErr: fmt.Errorf("some error"),
12341283
},
1284+
wantSubscriptions: []*v1alpha1.Subscription{
1285+
{
1286+
TypeMeta: metav1.TypeMeta{
1287+
Kind: v1alpha1.SubscriptionKind,
1288+
APIVersion: v1alpha1.SchemeGroupVersion.String(),
1289+
},
1290+
ObjectMeta: metav1.ObjectMeta{
1291+
Name: "sub",
1292+
Namespace: testNamespace,
1293+
},
1294+
Spec: &v1alpha1.SubscriptionSpec{
1295+
CatalogSource: "src",
1296+
CatalogSourceNamespace: testNamespace,
1297+
},
1298+
Status: v1alpha1.SubscriptionStatus{
1299+
CurrentCSV: "",
1300+
State: "",
1301+
Conditions: []v1alpha1.SubscriptionCondition{
1302+
{
1303+
Type: v1alpha1.SubscriptionResolutionFailed,
1304+
Reason: "ErrorPreventedResolution",
1305+
Message: "some error",
1306+
Status: corev1.ConditionTrue,
1307+
},
1308+
},
1309+
LastUpdated: now,
1310+
},
1311+
},
1312+
},
12351313
wantErr: fmt.Errorf("some error"),
12361314
},
12371315
}
@@ -1241,7 +1319,7 @@ func TestSyncResolvingNamespace(t *testing.T) {
12411319
ctx, cancel := context.WithCancel(context.TODO())
12421320
defer cancel()
12431321

1244-
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withK8sObjs(tt.fields.existingObjects...), withFakeClientOptions(tt.fields.clientOptions...))
1322+
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withFakeClientOptions(tt.fields.clientOptions...))
12451323
require.NoError(t, err)
12461324

12471325
o.reconciler = &fakes.FakeRegistryReconcilerFactory{
@@ -1254,7 +1332,6 @@ func TestSyncResolvingNamespace(t *testing.T) {
12541332
},
12551333
}
12561334

1257-
o.sourcesLastUpdate.Set(tt.fields.sourcesLastUpdate.Time)
12581335
o.resolver = &fakes.FakeStepResolver{
12591336
ResolveStepsStub: func(string) ([]*v1alpha1.Step, []v1alpha1.BundleLookup, []*v1alpha1.Subscription, error) {
12601337
return nil, nil, nil, tt.fields.resolveErr
@@ -1273,6 +1350,12 @@ func TestSyncResolvingNamespace(t *testing.T) {
12731350
} else {
12741351
require.NoError(t, err)
12751352
}
1353+
1354+
for _, s := range tt.wantSubscriptions {
1355+
fetched, err := o.client.OperatorsV1alpha1().Subscriptions(testNamespace).Get(context.TODO(), s.GetName(), metav1.GetOptions{})
1356+
require.NoError(t, err)
1357+
require.Equal(t, s, fetched)
1358+
}
12761359
})
12771360
}
12781361
}

‎pkg/controller/operators/catalog/subscriptions_test.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ func TestSyncSubscriptions(t *testing.T) {
2525
testNamespace := "testNamespace"
2626

2727
type fields struct {
28-
clientOptions []clientfake.Option
29-
sourcesLastUpdate metav1.Time
30-
resolveSteps []*v1alpha1.Step
31-
resolveSubs []*v1alpha1.Subscription
32-
bundleLookups []v1alpha1.BundleLookup
33-
resolveErr error
34-
existingOLMObjs []runtime.Object
35-
existingObjects []runtime.Object
28+
clientOptions []clientfake.Option
29+
resolveSteps []*v1alpha1.Step
30+
resolveSubs []*v1alpha1.Subscription
31+
resolveBundleLookups []v1alpha1.BundleLookup
32+
existingOLMObjs []runtime.Object
3633
}
3734
type args struct {
3835
obj interface{}
@@ -378,7 +375,7 @@ func TestSyncSubscriptions(t *testing.T) {
378375
},
379376
},
380377
},
381-
bundleLookups: []v1alpha1.BundleLookup{
378+
resolveBundleLookups: []v1alpha1.BundleLookup{
382379
{
383380
Path: "bundle-path-a",
384381
Identifier: "bundle-a",
@@ -1016,7 +1013,7 @@ func TestSyncSubscriptions(t *testing.T) {
10161013
ctx, cancel := context.WithCancel(context.TODO())
10171014
defer cancel()
10181015

1019-
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withK8sObjs(tt.fields.existingObjects...), withFakeClientOptions(tt.fields.clientOptions...))
1016+
o, err := NewFakeOperator(ctx, testNamespace, []string{testNamespace}, withClock(clockFake), withClientObjs(tt.fields.existingOLMObjs...), withFakeClientOptions(tt.fields.clientOptions...))
10201017
require.NoError(t, err)
10211018

10221019
o.reconciler = &fakes.FakeRegistryReconcilerFactory{
@@ -1029,10 +1026,9 @@ func TestSyncSubscriptions(t *testing.T) {
10291026
},
10301027
}
10311028

1032-
o.sourcesLastUpdate.Set(tt.fields.sourcesLastUpdate.Time)
10331029
o.resolver = &fakes.FakeStepResolver{
10341030
ResolveStepsStub: func(string) ([]*v1alpha1.Step, []v1alpha1.BundleLookup, []*v1alpha1.Subscription, error) {
1035-
return tt.fields.resolveSteps, tt.fields.bundleLookups, tt.fields.resolveSubs, tt.fields.resolveErr
1031+
return tt.fields.resolveSteps, tt.fields.resolveBundleLookups, tt.fields.resolveSubs, nil
10361032
},
10371033
}
10381034

0 commit comments

Comments
 (0)
Please sign in to comment.